2020. 2. 17. 11:16ㆍWPF/코드
- 도구상자 - DataGrid 선택
- WPF 폼에 위치
using System.Data;
namespace WPF
{
public partial class MainWindow : Window
{
// DataGrid , 데이터
DataTable dt = new DataTable();
public byte[,] tb_data;
public MainWindow()
{
Init_Variable();
InitializeComponent();
tb_data = new byte[16, 16];
dt.Columns.Add("ADDRESS", typeof(string));
for (int i = 0; i <= 0xF; i++)
{
dt.Columns.Add(i.ToString("X1"), typeof(string));
}
Update_DataGrid(tb_data);
Read_DataGrid(tb_data);
}
public void Update_DataGrid(byte[,] data )
{
string[] addr = new string[]
{
"00-0F", "10-1F", "20-2F", "30-3F", "40-4F",
"50-5F", "60-6F", "70-7F", "80-8F", "90-9F",
"A0-AF", "B0-BF", "C0-CF", "D0-DF", "E0-EF", "F0-FF"
};
string[] str = new string[16];
dt.Clear();
for (int i = 0; i <= 0xf; i++)
{
for (int j = 0; j <= 0xf; j++)
{
str[j] = data[i, j].ToString("X2");
}
dt.Rows.Add(new string[] { addr[i].ToString(), str[0], str[1], str[2], str[3], str[4], str[5], str[6], str[7], str[8], str[9], str[10], str[11], str[12], str[13], str[14], str[15] });
}
datagrid1.ItemsSource = dt.DefaultView;
}
public void Read_DataGrid(out byte[,] data, int max_row, int max_column)
{
int cnt_row = 0;
string str_print = null;
string[] addr = new string[] {
"00-0F", "10-1F", "20-2F", "30-3F", "40-4F",
"50-5F", "60-6F", "70-7F", "80-8F", "90-9F",
"A0-AF", "B0-BF", "C0-CF", "D0-DF", "E0-EF", "F0-FF"
};
data = new byte[max_row, max_column];
try
{
//wcb.WR_TextBox(logwindow.txt_String, "\r\n");
foreach (DataRowView row in datagrid1.Items)
{
cnt_row++;
str_print = "Address " + addr[cnt_row-1] + " : ";
for (int i = 1; i <= max_column; i++)
{
data[cnt_row - 1, i - 1] = Convert.ToByte(row.Row.ItemArray[i].ToString(), 16);
str_print += data[cnt_row - 1, i - 1].ToString("X2") + " ";
}
//wcb.WR_TextBox(logwindow.txt_String, str_print + "\r\n");
if ( cnt_row >= max_row )
{
cnt_row = 0;
break;
}
//wcb.WR_TextBox(logwindow.txt_String, "\r\n");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
}
'WPF > 코드' 카테고리의 다른 글
WPF___TextBox DragDrop 처리 (0) | 2021.01.19 |
---|---|
WPF___DataGrid & CheckBox Event (0) | 2020.02.17 |
WPF___닫힌 윈도우폼 열면 에러? (0) | 2020.02.17 |
WPF___백그라운드 프로세서 종료 (0) | 2020.02.17 |
WPF___Enum 반복 ( 나열 된 수 만큼 반복 ) (0) | 2020.02.17 |