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

row header text

38 Answers 1372 Views
GridView
This is a migrated thread and some comments may be shown as answers.
yarik
Top achievements
Rank 1
yarik asked on 08 Aug 2007, 11:08 AM
How can i add text to row header ?

38 Answers, 1 is accepted

Sort by
0
Dwight
Telerik team
answered on 08 Aug 2007, 01:29 PM
Hi Yarik,

One way to do this is to change the HeaderText property of the corresponding column:

radGridView1.MasterGridViewTemplate.Columns[0].HeaderText = "some text here"

If you have another scenario in mind, please, specify it so that we can further help you.
 

Regards,
Evtim
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
yarik
Top achievements
Rank 1
answered on 08 Aug 2007, 02:25 PM
I'm  mean how can i add text to row header not to column header
0
Dwight
Telerik team
answered on 09 Aug 2007, 08:16 AM
Hello Yarik,

There is no straight-forward way to add text to the row header as the text is not fixed (like the column headers). What you can do is subscribe to the RowFormatting event and control the cell in the header row.

Here is example, which copies the content of the first column into the header column:
 
private void radGridView1_RowFormatting(object sender, Telerik.WinControls.UI.RowFormattingEventArgs e) 
    GridRowHeaderCellElement grhce = e.RowElement.Children[0] as GridRowHeaderCellElement; 
 
    grhce.Text = string.Format("{0}", e.RowElement.RowInfo.Cells[0].Value); 
 

Currently the header row does not auto-resize. What you can do is set the width as you like through the theme (using say Visual Style Builder) or by code:
 
private void Form1_Load(EventArgs e) 
    (radGridView1.GridElement as GridTableElement).RowHeaderColumnWidth = 120; 

If you have further problems, write us back, we'll be glad to help.
 

Regards,
Evtim
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Officemate Public Company Limited
Top achievements
Rank 1
answered on 15 Sep 2008, 12:18 PM
And how to display text in column header of row header?
0
Jack
Telerik team
answered on 16 Sep 2008, 09:51 AM
Hi,

Thank you for this question.

You should process the ViewCellFormatting event and check whether the CellElement is GridTableHeaderCellElement. Consider the sample code below:

void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e) 
    if (e.CellElement is GridTableHeaderCellElement) 
    { 
        e.CellElement.Text = "Text"
    } 

I hope this helps. Should you have further questions, do not hesitate to ask.

 
All the best,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Officemate Public Company Limited
Top achievements
Rank 1
answered on 16 Sep 2008, 11:34 AM
and then next question.
How to alignment of CurrentRowHeaderImage to MiddleLeft, because now it display in MiddleCenter and show on RowHeaderText. It not so Cool!,help me please.
0
Jack
Telerik team
answered on 17 Sep 2008, 11:26 AM
Hi,

At this time RadGridView doesn't support image alignment in grid cells. We plan to implement this functionality in our upcoming release, due in a couple of months.


Greetings,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Peter Bogoyavlensky
Top achievements
Rank 1
answered on 05 Aug 2009, 06:45 AM

I am new with Telerik components and bring my apologies for my (probably) stupid question.

I want to write a number of row in row header column. Can you explain:

1. How can I find row number from RowFormattingEventArgs in RowFormatting event?

2. How can I renumber all rows in case of some row was inserted/deleted?

3. How can I prevent painting an image of pen (on row header cell) during editing some element in row?

0
Jack
Telerik team
answered on 05 Aug 2009, 08:59 AM
Hi Peter,

Regarding your questions:

1. You can get the row index by calling the IndexOf method of RadGridView.Rows collection. Look at the sample:

int rowIndex = this.radGridView1.Rows.IndexOf((GridViewDataRowInfo)e.RowElement.RowInfo); 
 

However, this method will be slow when the data source contains many rows. So, It will be better to add a hidden column that contains a pre-calculated row index.

2. This can be avoided when calculating the row index when requested. Otherwise, you should do this manually.

3. Just set the Image property of GridRowHeaderCellElement to null:

void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e) 
    if (e.CellElement is GridRowHeaderCellElement) 
    { 
        e.CellElement.Image = null
    } 

I hope this helps. Should you have any questions, don't hesitate to ask.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
MP
Top achievements
Rank 1
answered on 29 Sep 2010, 05:41 PM
Dear Telerik,

After upgrading to Q2-2010 SP2, we are unable to use this suggested method to display the row numbers on the row header because
the line below doesn't work anymore. It returns null instead of the Row Header Cell Element.
GridRowHeaderCellElement grhce = e.RowElement.Children[0] as GridRowHeaderCellElement;

What can we do to continue displaying the row numbers?

Regards,
MP
0
Jack
Telerik team
answered on 04 Oct 2010, 04:09 PM
Hi MP,

In our latest release we changed a bit the element hierarchy of RadGridView. This was necessary, because we introduced new features like cell virtualization and extended the frozen column and row functionality. Instead of using the Children collection you have to use the VisualCells one. However, It will be better to use the ViewCellFormatting event as I described in my previous post.

If you have further questions or need assistance, please do not hesitate to contact me.

All the best,
Jack
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bharghavi
Top achievements
Rank 1
answered on 28 Feb 2012, 07:11 AM
private void dgvResults_ViewCellFormatting(object sender, CellFormattingEventArgs e)
        {
            GridRowHeaderCellElement grhce = e.CellElement as GridRowHeaderCellElement;
            if (grhce != null && e.CellElement.RowInfo is GridViewDataRowInfo)
            {
                string RowNumber = (this.dgvResults.Rows.IndexOf(grhce.RowInfo) + 1).ToString();
                grhce.Text = RowNumber.ToString();
            }
        }

Telerik winform controls are upgraded to Q1 2012 version. After grouping the gridview by any column the row number in the rowheader.text is not renumbered for reach group.  

 

 

Example:
1 A
2 B
3 A

Results as

1 A
3 A

2 B

instead of

1 A
2 A

1 B

 

0
Jack
Telerik team
answered on 02 Mar 2012, 01:34 PM
Hi Bharghavi,

Yes, the described solution will work only when no sorting, grouping or filtering operation is applied on RadGridView. This is because the Rows collection contains all rows in the way they are seen in the underlying data source. You can access rows in the way they appear in RadGridView when using the ChildRows property. However, this collection is hierarchical. This means that when grouping applies this collection contains only the groups at the first level, to reach the data rows you should iterate the ChildRows property of every group row.

The following method will work in all cases:
public int GetRowNumber(RadGridView grid, GridViewRowInfo row)
{
    int index = 0;
    return GetRowNumberCore(row, grid.ChildRows, ref index);
}
 
private int GetRowNumberCore(GridViewRowInfo row, GridViewChildRowCollection childRows, ref int index)
{           
    foreach (GridViewRowInfo r in childRows)
    {
        if (r == row)
        {
            return index;
        }
        if (r is GridViewDataRowInfo)
        {
            index++;
        }
        int result = GetRowNumberCore(row, r.ChildRows, ref index);
        if (result != -1)
        {
            return result;
        }
    }
    return -1;
}

If you need further assistance, we will be glad to help.
 
Kind regards,
Jack
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Uday
Top achievements
Rank 1
answered on 06 Apr 2012, 10:39 AM
Hi telerik,



  How to change the gridveiw column header or Row header font size ?



0
Jack
Telerik team
answered on 09 Apr 2012, 12:25 PM
Hello Uday,

You can do this by handling the ViewCellFormatting event. Consider the following sample:
Font customHeaderFont = new Font("Comic Sans UI", 12f);
 
void radButton1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    GridHeaderCellElement cell = e.CellElement as GridHeaderCellElement;
    if (cell != null)
    {
        cell.Font = customHeaderFont;
    }
}

Find more about formatting cells in our online documentation.

All the best,
Jack
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Uday
Top achievements
Rank 1
answered on 09 Apr 2012, 01:06 PM
Hi jack,

thanks for your reply, i have a scenario where i have to display 3 comboboxes inside a single cell in a gridview. each comboboxes bounded to different data. how to achieve this using telerik gridview?


Thanks,
Uday
0
Nikolay
Telerik team
answered on 09 Apr 2012, 01:32 PM
Hello Uday,

Could you please let us know whether the comboboxes should be always visible, or should be visible only when the user enters the edit mode of RadGridView? Generally speaking the desired scenario is not supported out of the box, but the API of RadGridView may allow us to achieve something similar to what you require. In addition, describe how the values of these three comboboxes should be saved in a single cell. These details will allow us to discuss the case further.

A bit off topic, I would kindly ask you to open a new thread for each question that is not related to the main topic of an existing thread. This will allow the others interested in the same questions to find the answers more easily.

All the best,
Nikolay
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Uday
Top achievements
Rank 1
answered on 09 Apr 2012, 01:50 PM
hi Nikolay,

sorry for not opening in another thread, Actually i have to display 3 comboboxes in a single cell of a gridview in edit mode. i have already tried out this scenario and succeeded in displaying 3 comboboxes in a single cell of a gridview bt 2nd and 3rd comboxes not opening at all.


thanks
uday
0
Nikolay
Telerik team
answered on 10 Apr 2012, 12:04 PM
Hello Uday,

I suppose that the 2nd and the 3rd comboboxes are not opening, because they do not contain any data.
Please find attached a sample project which follows your scenario, but as you can see there, all comboboxes can be opened and they all contain data. You can follow my approach to get three combos at the same time in just one cell. You can also take a look at this article which covers the topic of creating a custom editor.

All the best,
Nikolay
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Uday
Top achievements
Rank 1
answered on 11 Apr 2012, 07:54 AM
Hi Nikolay,

Thanks, this solved my problem


Thanks,
Uday
0
Hugo Furth
Top achievements
Rank 1
answered on 08 May 2012, 04:55 PM
Is the _RowFormatting event still the preferred way to get text in the row header? If so, it doesn't seem to work for me. grhce is always null. Any advice?

Regards,
Hugo
0
Svett
Telerik team
answered on 11 May 2012, 02:00 PM
Hello Hugo,

If you want to format the row header text, you should use the ViewCellFormatting event.
void rgv_sample_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    GridRowHeaderCellElement headerCell = e.CellElement as GridRowHeaderCellElement;
 
    if (headerCell != null)
    {
        // TO DO:
    }
}

More information regarding row formatting, can be found here: http://www.telerik.com/help/winforms/gridview-rows-formatting-rows.html.

Let us know if you have any other questions.

Kind regards,
Svett
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
OPTCOM
Top achievements
Rank 1
answered on 30 May 2014, 09:13 AM
It's not necessary to add a special column at all. I do it using the following code . Hope to help you.


  private void radGridView1_ViewCellFormatting( object sender , CellFormattingEventArgs e )
        {
            if (e.CellElement is GridRowHeaderCellElement)
            {
                if ( e.CellElement.RowIndex != -1)
                {
                     e.CellElement.Text = ( e.CellElement.RowIndex + 1 ).ToString ( );
                     radGridView1.TableElement.RowHeaderColumnWidth = ( e.CellElement.RowIndex.ToString ( ).Length > 2 )
                       ? ( e.CellElement.RowIndex.ToString ( ).Length ) * rowHeaderCellWidth / 2
                       : rowHeaderCellWidth;
                }
                     
                
            }
             
           
        }

The variable rowHeaderCellWidth is the initial value of the row header width which you should get when the form is load.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Jun 2014, 02:30 PM
Hello Noah,

Thank you for sharing the code snippet with the community. In order to add some text to the row header, it is appropriate to use the RadGridView.ViewCellFormatting event as my colleague Svett suggested in the previous post:
public Form1()
{
    InitializeComponent();
    this.radGridView1.TableElement.RowHeaderColumnWidth = 50;
}
  
private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement is GridRowHeaderCellElement)
    {
        if (e.Row is GridViewDataRowInfo)
        {
            e.CellElement.Text = (e.CellElement.RowIndex + 1).ToString();
        }
    }
}

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
FE
Top achievements
Rank 1
answered on 04 Jul 2014, 08:29 AM

RowHeaderImage can textaligment left?
Thanks,
FE
0
FE
Top achievements
Rank 1
answered on 04 Jul 2014, 08:32 AM
image
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Jul 2014, 03:58 PM
Hello FE,

Thank you for writing.

It is necessary to extend the code snippet from my previous post, setting the CellElement.TextImageRelation property to ImageBeforeText in the ViewCellFormatting event.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Tim
Top achievements
Rank 1
answered on 19 Nov 2014, 03:37 PM
Hi Jack,
How to add a icon on RowHeader by double click this RowHeader?

Reagrds,
0
Tim
Top achievements
Rank 1
answered on 21 Nov 2014, 08:10 AM
How can I get rid of the arrow on the row header and add an icon to row header?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Nov 2014, 12:13 PM
Hello Tim,

Thank you for writing.

You can get rid of the arrow image or apply a different image which indicates the current row by setting the RadGridView.TableElement.CurrentRowHeaderImage property to null or desired image.
this.radGridView1.TableElement.CurrentRowHeaderImage = Properties.Resources.next;

Additionally, you can assign a header row image to all cells by using the ViewCellFormatting event and setting the Image property to all GridRowHeaderCellElements

I hope this information helps. Should you have further questions, I would be glad to help.Regards,
Desislava
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Tim
Top achievements
Rank 1
answered on 26 Nov 2014, 02:12 AM
Hello Desislava,

Thank you very much.  

I resolved my problems, thanks again for your help.

Best regards,
0
Tim
Top achievements
Rank 1
answered on 30 Nov 2014, 04:56 AM
Hello Desislava,

I'm in need of your help again.


I can apply a image to rowHeader or column[1] by CellClick or CellDoubleClick the current cell with your help, but it changes back when I Click other rows. How to add images to these cells what I clicked, just like the breakpoint of visual studio.

Additionally, I add the SelfReference to two columns which are invisiable. How to change the position of column[0],  just before the column "Test Items Description ". 

Thank you in advance.

Best regards,
 
0
Tim
Top achievements
Rank 1
answered on 30 Nov 2014, 05:02 AM
post the imag of my application
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Dec 2014, 04:39 PM
Hello Tim,

Thank you for writing back.

The appropriate way to apply an image to a specific cell is to use the CellFormatting event. Thus, when a certain cell is clicked, you can store the GridViewRowInfo and the column name of the cell. Afterwards, in the CellFormatting event you can set the image for the specified cell belonging to this row and column. Due to the UI virtualization in RadGridView, cell elements are created only for currently visible cells and are being reused during operations like scrolling, filtering, grouping and so on.
In order to prevent applying the formatting to other columns' cell elements (because of the cell reuse) all customization should be reset for the rest of the cell elements. Please refer to our Formatting Cells help article.

As to the question related to columns position, you can have a look at our Reordering Columns help article.

I hope this information helps. If you have any additional questions, please let me know.

Regards,
Desislava
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Aseman
Top achievements
Rank 1
Veteran
answered on 02 Sep 2019, 11:48 AM

hi dess

thank you for your answer

but i`ve a problem in this situation

when ever i have multi paging ,row index is reset per page 

please help me 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Sep 2019, 10:05 AM

Hello, Aseman,  

RadGridView exposes two collections that contain data rows:
- Rows - contains all data rows that belong to RadGridView. Data operations such as grouping, sorting, filtering, etc. do not change the content of the collection or the order in which the row objects exist in the collection.
- ChildRows - returns the data rows that are currently represented by RadGridView in the order in which they appear. The collection is modified every time a data operation (grouping, sorting, filtering) occurs.

Similar to filtering, sorting and grouping, the ChildRows collection is affected by the paging as well and it contains only the records on the current page. A common scenario is to access the real row index when the paging is enabled in the order the items appear in the grid.

The RadGridView.MasterTemplate.DataView.Indexer offers the Items collection which contains all the rows in the order in which they appear in the grid. The collection is affected every time a data operation like grouping, sorting, filtering occurs. You can use it to extract the correct index when moving through the pages:

 

        private void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
        {
            if (e.CellElement is GridRowHeaderCellElement && e.Row is GridViewDataRowInfo)
            {
                GridDataView dataView = this.radGridView1.MasterTemplate.DataView as GridDataView;
                e.CellElement.Text = (dataView.Indexer.Items.IndexOf(e.Row) + 1).ToString();
                e.CellElement.TextImageRelation = TextImageRelation.ImageBeforeText;
            }
            else
            {
                e.CellElement.ResetValue(LightVisualElement.TextImageRelationProperty, ValueResetFlags.Local);
            }
        }

I hope this information helps. If you need any further assistance please don't hesitate to contact me.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Robert
Top achievements
Rank 1
answered on 08 Sep 2020, 11:48 PM
The DataView.Indexer doesn't seem to contain items in the order in which they appear in the grid if the grid is grouped. Am I missing anything ?

I am just testing that: as my grid is displayed, one of the rows in the second group is the first item in DataView.Indexer collection. That right there seems to contradict the above answer. Or from another angle: the first group has 5 records. Doesn't it mean that the first record in the second group would be DataView.Indexer[5] (assuming the group header rows don't count (btw, do they count ?) )..
0
Nadya | Tech Support Engineer
Telerik team
answered on 11 Sep 2020, 01:40 PM

Hello, Robert,

The RadGridView.MasterTemplate.DataView.Indexer offers the Items collection which contains all the rows in the order in which they appear in the grid. The collection is affected every time a data operation like grouping, sorting, filtering occurs. The Indexer can not be accessed by index as you suggested.

If you want to access the rows after grouping you should use the ChildRows collections. The collection is modified every time a data operation (grouping, sorting, filtering) occurs. More information and examples are available here: https://docs.telerik.com/devtools/winforms/controls/gridview/rows/rows-vs-childrows

I hope this helps. Let me know if you need further assistance.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
yarik
Top achievements
Rank 1
Answers by
Dwight
Telerik team
yarik
Top achievements
Rank 1
Officemate Public Company Limited
Top achievements
Rank 1
Jack
Telerik team
Peter Bogoyavlensky
Top achievements
Rank 1
MP
Top achievements
Rank 1
Bharghavi
Top achievements
Rank 1
Uday
Top achievements
Rank 1
Nikolay
Telerik team
Hugo Furth
Top achievements
Rank 1
Svett
Telerik team
OPTCOM
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
FE
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Aseman
Top achievements
Rank 1
Veteran
Robert
Top achievements
Rank 1
Nadya | Tech Support Engineer
Telerik team
Share this question
or