[C# WinForm]
Regarding the Row Header (as shown in the figure below: (R1, R2, R3,...)
Question:
- How to get the Text of the Row Header? - E.g. string rowHeaderText = radGridView1.Rows[0].......
Reference:
https://www.telerik.com/forums/radgridview-row-header-related-questions
Based on the reference topic, I have attempted the to get the Row Header using Visual Rows.
var cellContent = this.radGridView1.TableElement.VisualRows[0].VisualCells[0].Text;
But seems like the VisualRows doesn't reflect all the rows.
For example, I have populated 77 rows as shown in first figure below.
However, the count of VisualRows is 4 only (as shown in second figure).
Formatting Row Header:
private void dgvMap_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
if (e.CellElement is GridRowHeaderCellElement)
{
e.CellElement.Text = string.Format("R{0}", dgvMap.CurrentView.ViewInfo.Rows.IndexOf(e.Row) + 1);
var element = new RadButtonElement();
element.Margin = new Padding(3, 3, 3, 3);
element.Padding = new Padding(2, 0, 2, -2);
element.ImageAlignment = ContentAlignment.MiddleCenter;
element.Alignment = ContentAlignment.MiddleCenter;
element.ForeColor = Color.Black;
element.Text = string.Format("R{0}", dgvMap.CurrentView.ViewInfo.Rows.IndexOf(e.Row) + 1);
element.AutoSizeMode = RadAutoSizeMode.Auto;
element.MinSize = new Size(80, 50);
e.CellElement.Children.Add(element);
e.CellElement.ForeColor = Color.White;
}
Populating Rows & Columns:
numberOfRow = int.Parse(maxRow);
numberOfColumn = int.Parse(maxCol);
for (int j = 1; j <= numberOfColumn; j++)
dgvMap.Columns.Add(string.Format("C{0}", j));
for (int k = 1; k <= numberOfRow; k++)
{
dgvMap.Rows.Add(new string[] { "" });
}
for (int k = 1; k <= numberOfRow; k++)
{
for (int j = 1; j <= numberOfColumn; j++)
{
string key = string.Format("{0},{1}", this.dgvMap.TableElement.VisualRows[k-1].VisualCells[0].Text, dgvMap.Columns[j - 1].Name);
}
}