1.girdView在第一列显示行号
//调整第一列的宽度
this.gridView1.IndicatorWidth = 40;
private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
{
e.Info.DisplayText = (e.RowHandle+1).ToString();
}
}
2. 点击 gridView 列的单击事件获取自定列信息
private void gridControl1_Click(object sender, EventArgs e)
{
//方法1
if (gridView1.GetFocusedRow() != null)
{
HisCashsClass dr = (HisCashsClass)(gridView1.GetFocusedRow());
MessageBox.Show(dr.EN_CURRENT_BALANCE.ToString());
//方法2
//string name = "";
//foreach (int rowId in gridView1.GetSelectedRows())
//{
// foreach (GridColumn col in gridView1.VisibleColumns)
// {
// name = gridView1.GetRowCellValue(rowId, gridView1.Columns["EN_CURRENT_BALANCE"]).
// ToString();
// }
//}
//MessageBox.Show(name);
}
}
3.根据指定条件设置单元格字体前景色
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (e.Column.GetCaption() == "当前金额" && Convert.ToDouble(e.CellValue)<20000)
{
e.Appearance.ForeColor = Color.Blue;
}
}
4. 显示的数据隔行斑马线显示方式
需要将 OptionsView——EnableAppearanceEvenRow/EnableAppearanceOddRow 两个属性设为 True( 默认为 false) ,然后再设置 Appearance 里 EvenRow 和 OddRow 颜色就可以了。
本文介绍了使用GridView进行自定义显示的方法,包括设置行号显示、获取点击列的信息、设置单元格字体颜色以及实现斑马线显示效果。通过具体代码示例展示了如何实现这些功能。

3847

被折叠的 条评论
为什么被折叠?



