1.获取GridControl 中的全部显示内容
DataTable dt=gridControl.DataSource ;//数据源为DataTable
注意:这个获取数据源的办法是根据数据源的类型获取,这里小编用的是DataTable
2.获取GridControl 中选中多行的数据内容
List<Dictionary<string, string>> listCheckMat = new List<Dictionary<string, string>>();
//gv焦点清空让最后一次选择的行选中
gv.FocusedRowHandle = -1;
//获取选中行的内容
for (int i = 0; i < gv.DataRowCount; i++)
{
if ((bool)gvMatMain.GetDataRow(i)["选择"])
{
Dictionary<string, string> item = new Dictionary<string, string>();
item.Add("mat_no", gvMatMain.GetDataRow(i)["A"].ToString());
item.Add("mat_kind", gvMatMain.GetDataRow(i)["B"].ToString());
listCheckMat.Add(item);
}
}
3.获取GridControl 中选中单行数据内容
private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
int intRowHandle = e.FocusedRowHandle;
if (intRowHandle < 0)
{
return;
}
string A = gridView1.GetRowCellValue(intRowHandle, "A").ToString();
string B= gridView1.GetRowCellValue(intRowHandle, "B").ToString();
string C = gridView1.GetRowCellValue(intRowHandle, "C").ToString();
string D = gridView1.GetRowCellValue(intRowHandle, "D").ToString();
}