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

Display row number on the row header

5 Answers 290 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Amit Patel
Top achievements
Rank 1
Amit Patel asked on 28 Nov 2011, 08:42 PM
Hello,
Is there a way to display a row number on the row header? I have a hierarchical grid and like to display number of the row header. I don't want to add additional column to display row number, indead I like them to be on row header.

Thanks,
Amit

5 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 29 Nov 2011, 09:09 AM
Hello Amit Patel,


 
Will you please share with us what should be the exact desired result when the row number is displayed within GridViewHeaderRow? Imagine that you have 100 items and 10 columns, so what do you expect to see in this part of RadGridView? What you may do is to keep a separate column and transpose the rows into columns and vice versa. You may take a look at the following blog post which demonstrates how this can be achieved.
 
 


Kind regards,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Amit Patel
Top achievements
Rank 1
answered on 29 Nov 2011, 03:50 PM
It simply comes to down to usability issue. When two people open same file at separate locations, it’s easy to tell other what row they are working on. I have managed to pull off displaying row number, but seeing some weirdness when grid is hierarchical, the row numbers keep on increasing. See the attached images. I do now want to add another column to display row number, I think; it will just take extra real estate. I want it to look just like excel.

Thanks,
Amit
0
Vanya Pavlova
Telerik team
answered on 29 Nov 2011, 04:00 PM
Hi Amit Patel,


Looking at your pictures I am not quite sure whether you refer either to RadGridView or TreeListView component. Will you please share with us a bit more info about your exact settings?
Any relevant snippet or sample project in a new support ticket might be of help on that matter. 


All the best,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Amit Patel
Top achievements
Rank 1
answered on 05 Jan 2012, 04:40 PM
Here is the code that I put it on gridview rowloaded event to add row number. if I am loading let say 1000 rows then row number are not displayed in correct order. It seems that RowLoaded event doesn't get fire in same order.  Can you tell me what would good way to do this?

Thanks,
Amit
private void GridViewDataControl_RowLoaded(object sender, RowLoadedEventArgs e) {
var gridViewRow = e.Row as GridViewRow; 
if (gridViewRow != null)
{
var border = gridViewRow .ChildrenOfType<Border>() .Where(b => b.Name == "PART_IndicatorPresenter") .FirstOrDefault();
if (border != null)
{ var innerBorder = border.Child as Border;
if (innerBorder != null && !(innerBorder.Child is TextBlock))
{
                                var textBlock = new TextBlock();
                                textBlock.TextAlignment = TextAlignment.Center;
                                textBlock.VerticalAlignment = VerticalAlignment.Center;
                                textBlock.Text = (_target.Items.IndexOf(gridViewRow.Item) + 1).ToString();
                                innerBorder.Child = textBlock;
                        }
                }    
        }
}
0
Vanya Pavlova
Telerik team
answered on 05 Jan 2012, 05:15 PM
Hi,

 

Generally the approach you have used is not the recommended one. RowLoaded event is fired each time a row appears within the viewport and you are adding visual elements to it. It would be much more appropriate to incorporate this TextBlock in the template of GridViewRow and set its Text property to the index of the corresponding item. I am attaching you sample project which demonstrates how this can be achieved.  



Greetings,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Amit Patel
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Amit Patel
Top achievements
Rank 1
Share this question
or