c# DevExpress 网格关系:如何使 GridView 显示行数?



如何在下面的附加文件之后在子/孙子的标题上显示行号?

上面的代码仅适用于gridView1_CustomDrawRowIndicator,但不适用于孩子的自定义绘制行指示器事件。使用该代码的结果是行号以 0 开头,如何使其以 1 开头,就像此链接中的结果一样 https://www.codeproject.com/Tips/835501/Master-Detail-Datagridview 和 https://www.codeproject.com/Tips/1215736/Master-Detail-Datagridview-in-Csharp

单击此处显示图像 以下是以下代码的结果:

private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
{
GridView gv = (GridView)sender;
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
{
e.Info.DisplayText = e.RowHandle.ToString();
e.Info.Appearance.Font = new Font("CordiaUPC", 12);
e.Info.Appearance.Options.UseFont = true;
e.Info.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
if (!indicatorIcon)
e.Info.ImageIndex = -2;
}
}
private void gridView2_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
{
GridView gv = (GridView)sender;
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
{
e.Info.DisplayText = e.RowHandle.ToString();
e.Info.Appearance.Font = new Font("CordiaUPC", 12);
e.Info.Appearance.Options.UseFont = true;
e.Info.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
if (!indicatorIcon)
e.Info.ImageIndex = -2;
}
}           
private void gridView3_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
{
GridView gv = (GridView)sender;
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
{
e.Info.DisplayText = e.RowHandle.ToString();
e.Info.Appearance.Font = new Font("CordiaUPC", 12);
e.Info.Appearance.Options.UseFont = true;
e.Info.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
if (!indicatorIcon)
e.Info.ImageIndex = -2;
}
}

我尝试了这段代码,但它是在列上添加行号,但我需要的是在行标题上显示行号。

private void gridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
{
e.DisplayText = e.RowHandle.ToString();
}

单击此处显示图像

请从此参考中尝试这样做。 https://www.devexpress.com/Support/Center/Question/Details/T126680/auto-row-number-in-grid

gridView1.IndicatorWidth = 30;
void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
{
if(e.RowHandle >= 0 )
e.Info.DisplayText = e.RowHandle.ToString();
}

最新更新