1、GridControl控件使用
(1)綁定數據源
//綁定DataTable
gridControl1.DataSource = DbHelper.ExecuteDataTable("SELECT * FROM dc_Log");
(2)配置顯示列
(3)插入按鈕列
(4)插入復選框CheckBox
(5)獲取操作按鈕列的值
設置按鈕事件
獲取當前行的值
private void repositoryItemButtonEdit1_Click(object sender, EventArgs e)
{
//獲取點擊行的索引
int RowIndex = gridView1.GetFocusedDataSourceRowIndex();
//輸出值
MessageBox.Show(gridView1.GetRowCellValue(RowIndex, "LogId").ToString());
}
(6)獲取CheckBox的值
設置批量操作按鈕
按鈕點擊事件
private void simpleButton1_Click(object sender, EventArgs e)
{
//獲取所選擇的行
int[] rows = gridView1.GetSelectedRows();
foreach(int i in rows)
{
//輸出值
MessageBox.Show(gridView1.GetRowCellValue(i, "LogId").ToString());
}
}
(7)設置Dock屬性