如何在下面的附加文件后的Child / GrandChild标题上显示行号?
上面的代码仅适用于gridView1_CustomDrawRowIndicator,但不适用于Child的CustomDrawRowIndicator事件。使用该代码的结果是行号以0开头,如何使其以1开头,如此链接https://www.codeproject.com/Tips/835501/Master-Detail-Datagridview和https://www.codeproject.com/Tips/1215736/Master-Detail-Datagridview-in-Csharp
中的结果Click Here to show the image 这是以下代码的结果:
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;
}
}
我尝试了这段代码,但是它是在Columns上添加行号,但是我需要在行标题上显示行号。
private void gridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
{
e.DisplayText = e.RowHandle.ToString();
}
答案 0 :(得分:0)
请从此参考资料中尝试这样。 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();
}