DEV--GerdView控件

时间:2023-03-09 08:29:18
DEV--GerdView控件

1.遍历

for (int i = ; i < gridView1.RowCount; i++)
{
for (int j = ; j < gridView1.Columns.Count; j++)
{
object val = gridView1.GetRowCellValue(i, gridView1.Columns[j]);
}
}

2.为某行设置背景色

 private void gridView1_RowStyle(object sender, RowStyleEventArgs e)
{
GridView View = sender as GridView; if (e.RowHandle >= )
{
string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["允许打印"]); if (category == "是")
{
e.Appearance.BackColor = Color.Salmon; e.Appearance.BackColor2 = Color.SeaShell;
}
}
}

3.上一条和下一条

public void PlayBefore(){
//当前行
int selectedIndex=this.gridView1.FocusedRowHandle;
if(selectedIndex==){
XtraMessageBox.Show("已经是第一条","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
//选择上一行
this.gridView1.FocusedRowHandel=this.gridView.FocusedRowHandle-;
this.gridView1.ClearSellection();
this.gridView1.SelectRow(this.gridView1.FocusedRowHandle);
}
public void PlayNext(){
//当前行
int selectedIndex=this.gridView1.FocusedRowHandle;
if(selectedIndex==this.gridView1.RowCount-){
XtraMessageBox.Show("已经是最后一条","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
//选择下一行
this.gridView1.FocusedRowHandel=this.gridView.FocusedRowHandle+;
this.gridView1.ClearSellection();
this.gridView1.SelectRow(this.gridView1.FocusedRowHandle);
}

4.获取当前行

int focusRowIndex=this.gridView1.GetFocusedDataSourceRowIndex();
DataModel model=this.gridView1.GetRow(focusRowIndex) as DataModel;

5.自定义排序

private void gridView1_CustomColumnSort(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnSortEventArgs e)
{
if (e.Column != null && e.Column.FieldName == "FieldName")
{
int value1 = Convert.ToInt32(e.Value1.ToString());
int value2 = Convert.ToInt32(e.Value1.ToString()); e.Result = System.Collections.Comparer.Default.Compare(value1, value2);
e.Handled = true;
}
}

6.复制表格

 private string CopyGrid()
{
MemoryStream memoryStream = new MemoryStream();
gridControl1.ExportToText(memoryStream);
memoryStream.Position = ;
byte[] read = new byte[memoryStream.Length];
memoryStream.Read(read, , read.Length);
string content = Encoding.Default.GetString(read);
return content;
}

7.ColumnPositionChanged

DEV--GerdView控件

DEV--GerdView控件