row header text

35 posts, 0 answers
  1. yarik
    yarik avatar
    14 posts
    Member since:
    Aug 2007

    Posted 08 Aug 2007 Link to this post

    How can i add text to row header ?
  2. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 08 Aug 2007 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. yarik
    yarik avatar
    14 posts
    Member since:
    Aug 2007

    Posted 08 Aug 2007 Link to this post

    I'm  mean how can i add text to row header not to column header
  5. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 09 Aug 2007 Link to this post

    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
  6. Officemate Public Company Limited
    Officemate Public Company Limited avatar
    4 posts
    Member since:
    Sep 2008

    Posted 15 Sep 2008 Link to this post

    And how to display text in column header of row header?
  7. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 16 Sep 2008 Link to this post

    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.
  8. Officemate Public Company Limited
    Officemate Public Company Limited avatar
    4 posts
    Member since:
    Sep 2008

    Posted 16 Sep 2008 Link to this post

    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.
  9. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 17 Sep 2008 Link to this post

    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.
  10. Peter Bogoyavlensky
    Peter Bogoyavlensky avatar
    20 posts
    Member since:
    Feb 2009

    Posted 05 Aug 2009 Link to this post

    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?

  11. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 05 Aug 2009 Link to this post

    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.
  12. MP
    MP avatar
    22 posts
    Member since:
    May 2009

    Posted 29 Sep 2010 Link to this post

    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
  13. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 04 Oct 2010 Link to this post

    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
  14. Bharghavi
    Bharghavi avatar
    1 posts
    Member since:
    Aug 2011

    Posted 28 Feb 2012 Link to this post

    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

     

  15. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 02 Mar 2012 Link to this post

    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 >>
  16. Uday
    Uday avatar
    6 posts
    Member since:
    Jun 2012

    Posted 06 Apr 2012 Link to this post

    Hi telerik,



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



  17. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 09 Apr 2012 Link to this post

    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 >>
  18. Uday
    Uday avatar
    6 posts
    Member since:
    Jun 2012

    Posted 09 Apr 2012 Link to this post

    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
  19. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 09 Apr 2012 Link to this post

    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 >>
  20. Uday
    Uday avatar
    6 posts
    Member since:
    Jun 2012

    Posted 09 Apr 2012 Link to this post

    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
  21. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 10 Apr 2012 Link to this post

    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 >>
  22. Uday
    Uday avatar
    6 posts
    Member since:
    Jun 2012

    Posted 11 Apr 2012 Link to this post

    Hi Nikolay,

    Thanks, this solved my problem


    Thanks,
    Uday
  23. Hugo Furth
    Hugo Furth avatar
    31 posts
    Member since:
    Dec 2008

    Posted 08 May 2012 Link to this post

    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
  24. Svett
    Admin
    Svett avatar
    728 posts

    Posted 11 May 2012 Link to this post

    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 >>
  25. noah
    noah avatar
    2 posts
    Member since:
    Apr 2014

    Posted 30 May 2014 Link to this post

    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.
  26. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 03 Jun 2014 Link to this post

    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.
     
  27. FE
    FE avatar
    2 posts
    Member since:
    Jul 2014

    Posted 04 Jul 2014 in reply to Dess Link to this post


    RowHeaderImage can textaligment left?
    Thanks,
    FE
  28. FE
    FE avatar
    2 posts
    Member since:
    Jul 2014

    Posted 04 Jul 2014 in reply to Dess Link to this post

    image
  29. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 04 Jul 2014 Link to this post

    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.
     
  30. Tim
    Tim avatar
    8 posts
    Member since:
    Jul 2014

    Posted 19 Nov 2014 in reply to Jack Link to this post

    Hi Jack,
    How to add a icon on RowHeader by double click this RowHeader?

    Reagrds,
  31. Tim
    Tim avatar
    8 posts
    Member since:
    Jul 2014

    Posted 21 Nov 2014 Link to this post

    How can I get rid of the arrow on the row header and add an icon to row header?
Back to Top
UI for WinForms is Visual Studio 2017 Ready