作者:1237i | 来源:互联网 | 2023-08-31 13:11
一:Clone返回新的 DataTable
Clone返回新的 DataTable,与当前的 DataTable 具有相同的架构;Copy:返回新的 DataTable,它具有与该 DataTable 相同的结构(表架构和约束)和数据
DataRow[] _dr = DT.Select("CLSSBH='"+ Filter_Str +"'");
DataTable dt = DT.Clone() ;
DataRow dr ;
for( int j &#61; 0 ;j <_dr.Length ;j &#43;&#43; )
{
dr &#61; dt.NewRow() ;
dr &#61; _dr[j] ;
dt.ImportRow( dr ) ;
}
我一般使用DataTable.Rows.Add(row.ItemArray);
二&#xff1a;选中某一行
GridView.FocusedRowHandle &#61;i;
GridView.SelectRow(i);
三&#xff1a;遍历GridView
for (int i &#61; 0; i {
for (int j &#61; 0; j {
object val &#61; gridView1.GetRowCellValue(i, gridView1.Columns[j]);
}
}
四&#xff1a;单元格双击响应
需要先将gridview1.OptionsBehavior.Editable设为false,然后响应gridControl1_DoubleClick事件。
private void gridControl1_DoubleClick(object sender, EventArgs e)
{
MouseEventArgs arg &#61; e as MouseEventArgs;
if (arg &#61;&#61; null)
return;
GridHitInfo hitInfo &#61; gridView1.CalcHitInfo(new Point(arg.X, arg.Y));//获取坐标点
if (hitInfo.RowHandle >&#61; 0)
{
DataRow row &#61; gridView1.GetDataRow(hitInfo.RowHandle);
_list.Clear();
_list.Add(row[0].ToString());
gisResoureMonControl1.SetSelectResource(_list);
}
}
五&#xff1a;GridView隐藏行
需要响应CustomRowFilter事件&#xff0c;用来设置过滤条件&#xff1b;
需要根据原始数据源结合起来&#xff0c;才能方便地隐藏或者显示行&#xff1b;
///
/// 根据条件查询并在表格中显示结果
///
///
private void QueryTable(string strCondition)
{
DataTable table &#61; gridControl1.DataSource as DataTable;
if (table &#61;&#61; null)
return;
_indexlist.Clear();
for (int i &#61; 0; i
{
for (int j &#61; 0; j
{
if(table.Rows[i][j].ToString().Contains(strCondition))
{
_indexlist.Add(i);
gridView1.RefreshData();
break;
}
}
}
if (_indexlist.Count&#61;&#61;0)
HideGridView();
}
///
/// gridView的行隐藏或显示的过滤条件
///
///
///
private void gridView1_CustomRowFilter(object sender, RowFilterEventArgs e)
{
if (_indexlist.Count &#61;&#61; 0)
return;
if(_indexlist.Contains(-2))
e.Visible &#61; true; //全显示
else if (_indexlist.Contains(-3))
e.Visible &#61; false; //全隐藏
else if(_indexlist.Contains(e.ListSourceRow))
e.Visible &#61; true;
else
e.Visible &#61; false;
e.Handled &#61; true;
}