This is a migrated thread and some comments may be shown as answers.

Set Row Header

5 Answers 420 Views
GridView
This is a migrated thread and some comments may be shown as answers.
stewart
Top achievements
Rank 1
stewart asked on 14 Feb 2008, 11:17 PM
Prior to using RadGridView, i made use of the new DataGridView in .NET 2.0.

consider the code below, where i successfully populate the row headers:

string[] userInputParams = new string[] {"apples","oranges",
                                                              "mangos",
                                                              "guanábana"}
 for (int i = 0; i < userInputParams.Length; i++)
 {
                gridRows.Add();
                gridRows[i].HeaderCell.Value = userInputParams[i];
}

How would i acheive this with the telerik RadGridView winform control?

thank you

5 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 15 Feb 2008, 09:25 AM
Hi stewart,

Thank you for writing us.

In RadGridView you achieve this behavior by using the HeaderText property of the GridViewColumn. Consider the following code snippet:

this.radGridView1.DataSource = table; 
this.radGridView1.Columns[0].HeaderText = "apples"
this.radGridView1.Columns[1].HeaderText = "oranges"
this.radGridView1.Columns[2].HeaderText = "mangos"
this.radGridView1.Columns[3].HeaderText = "guanábana"
 

Let us know if you have any other questions.

Regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
stewart
Top achievements
Rank 1
answered on 15 Feb 2008, 02:12 PM
Hi Jack,

Thank you for your quick reply.  The code you supplied will
set the column headers, while my code, if you notice, is accessing
the HeaderText property for individual gridRows (a row collection)
items.  The end goal is to set the row header.

i have been unable to reference the row header directly.
I  tried using the GridRowHeaderCellElement constructor,
with no success.

I've resorted to a solution that employs the radGridView1_RowFormatting
event as per the forum posting: http://www.telerik.com/community/forums/thread/b311D-heamc.aspx

I am using the trial version of 'RadControls for WinForms Q3 2007 SP1',
is there an updated release, perhaps a Q1 2008?  I am very interested
in your product, and would like to incorporate it into our solutions.

once again,

thank you,

stewart
0
Jack
Telerik team
answered on 17 Feb 2008, 04:22 PM
Hello Stewart,

I apologise as I didn't understand your question the first time. You can access the row header cell by processing the CellFormatting event. Consider the code snippet below:

this.radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting); 
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
    if (e.CellElement is GridRowHeaderCellElement) 
    { 
        e.CellElement.BackColor = Color.Red; 
        e.CellElement.DrawFill = true
    } 
 

Don't hesitate to write us if you have other questions.

Regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Kalpana
Top achievements
Rank 1
answered on 17 Nov 2012, 12:49 PM
Hi Jack,

I'm using RadGridView WinForms, I want to show row numbers in row header similar to row numbers shown in excel. Apart from cell formatting event code you shared in your previous thread is there any syntax to explicitly set row as row header? Please help with syntax how to set row header after radGridView1.Rows.AddNew(); 

Thanks in advance.

0
Jack
Telerik team
answered on 21 Nov 2012, 01:54 PM
Hi Kalpana,

There is no dedicated row number column in RadGridView. The best way to do this is by handling the CellFormatting event. Consider the sample below:
this.radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting);
this.radGridView1.Columns.Insert(0, new GridViewTextBoxColumn("RowHeader") { ReadOnly = true, HeaderText = " " } );
 
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    GridDataCellElement cell = e.CellElement as GridDataCellElement;
    if (cell.ColumnInfo.Name == "RowHeader")
    {
        cell.Text = cell.RowInfo.Index.ToString();
    }
}

I hope it helps.
 
Greetings,
Jack
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
GridView
Asked by
stewart
Top achievements
Rank 1
Answers by
Jack
Telerik team
stewart
Top achievements
Rank 1
Kalpana
Top achievements
Rank 1
Share this question
or