DataTable table = new DataTable(); //테이블 생성 public Save_Record() { InitializeComponent(); save_record_view.RowHeadersVisible = false; // 첫번째 콜롬 안보이게 save_record_view.ReadOnly = true; // 값들 편집 불가능하게 save_record_view.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; // 콜롬 이름 중앙 정렬 save_record_view.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; // 셀 값들 중앙 정렬 // 열 생성 table.Columns.Add(new DataColumn("Set", typeof(string))); table.Columns.Add(new DataColumn("Name", typeof(string))); table.Columns.Add(new DataColumn("Date", typeof(string))); table.Columns.Add(new DataColumn("Comment", typeof(string))); // 데이터 가져오기 Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client(); int redordsLength = client.Load_DB_Record().Length; string[] data = new string[redordsLength]; data = client.Load_DB_Record(); int col = 4; int row = redordsLength / 4; string[,] records = new string[row, col]; int index = 0; for (int r = 0; r < row; r++) { for (int c = 0; c < col; c++) { records[r, c] = data[index]; index++; } } // 데이터 테이블에 값 넣기 DataRow dataRow = null; for (int r = 0; r < row; r++) { dataRow = table.Rows.Add(); for (int c = 0; c < col; c++) { dataRow[c] = records[r, c]; } } save_record_view.DataSource = table; // grid view 에 데이터 불러옴 //save_record_view.CurrentCell = null; // 선택 해제 }
public DB_Load() { InitializeComponent(); load_clicked = false; // combo box에 띄울 set, 이름, comment 불러오기 Linelist_WCF.Service1Client client = new Linelist_WCF.Service1Client(); int recordsLength = client.Load_DB_Record().Length; string[] data = new string[recordsLength]; data = client.Load_DB_Record(); int col = 4; int row = recordsLength / 4; string[,] records = new string[row, col]; int index = 0; for (int r = 0; r < row; r++) { for (int c = 0; c < col; c++) { records[r, c] = data[index]; index++; } } index = 0; string[] str = new string[row]; for (int r = 0; r < row; r++) { for (int c = 0; c < col; c++) { if (c == 0 || c == 1) { str[index] += (records[r, c].Replace("\n", string.Empty) + " / "); } else if (c == 3) { str[index] += records[r, c].Replace("\n", string.Empty); } } index++; } load_data_select_combobox.Items.AddRange(str); // combo box에 값 추가 }