事件
根据状态显示要设置行的颜色
private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{
GridView View = senderas GridView;
if (e.RowHandle >= 0)
{
string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["AUTHSTATUSDESC"]);
if (category =="认证未通过")
{
e.Appearance.BackColor =Color.Crimson;
e.Appearance.BackColor2 =Color.SeaShell;
}
else if (category == "认证通过")
{
e.Appearance.BackColor =Color.DeepSkyBlue;
e.Appearance.BackColor2 =Color.SeaShell;
}
}
}
双击行时,显示对应的TabPage页
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left && e.Clicks == 2
{
XtraTabControl1.SelectedTabPage = pageDetail;
}
}
此功能同DoubleClick事件
private void gridView1_DoubleClick(object sender,EventArgs e)
{
XtraTabControl1.SelectedTabPage = pageDetail;
}
如何在查询得到0条记录时显示自定义的字符提示/显示
private void gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
{
if (this.gridView1.RowCount == 0)
{
string str = "没有符合条件的数据!";
System.Drawing.Font f = new System.Drawing.Font("宋体", 10, FontStyle.Bold);
Rectangle r = new Rectangle(e.Bounds.Left + 5, e.Bounds.Top + 5, e.Bounds.Width - 5, e.Bounds.Height - 5);
e.Graphics.DrawString(str, f, Brushes.Black, r);
}
}
显示水平滚动条
设置this.gridView1.OptionsView.ColumnAutoWidth = false;
或 设置Run Design->OptionsView->ColumnAutoWidth 设置为:false
定位到第一条数据/记录?
设置 this.gridView.MoveFirst()
定位到下一条数据/记录?
设置 this.gridView.MoveNext()
定位到最后一条数据/记录?
设置 this.gridView.MoveLast()