Buttons in header (or toolbar)

18 posts, 1 answers
  1. Francois
    Francois avatar
    52 posts
    Member since:
    Dec 2010

    Posted 16 Dec 2011 Link to this post

    Hi, is there a way to achieve something like that in WinForms?

    http://blogs.telerik.com/blogs/posts/10-01-22/math-toolbar-for-column-headers-in-radgridview-for-silverlight.aspx

    Thanks,
  2. Answer
    Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 21 Dec 2011 Link to this post

    Hi Francois,

    Thank you for writing.

    The same scenario is easily achievable with our controls for win forms. Please find attached a sample project where I have implemented a similar column header cell in the RadGridView. What I have done is create a custom header cell element and replaced the original one in the RadGridView CreateCell. I have also increased the RadGridView header row height so it could accommodate the additional elements. 

    I hope this is what you are looking for. If you have further questions, I would be glad to help.

    All the best,
    Ivan Petrov
    the Telerik teamQ3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Michał
    Michał avatar
    2 posts
    Member since:
    Mar 2013

    Posted 11 Mar 2013 Link to this post

    Hi 
    I have used your code but users have found another problem ...
    If there is horizontal scrollbar on grid, and if You scroll/move grid, header buttons are displayed in random columns.

    Just use existing example add more columns and set width to it so whole grid is longer than window and horizontal scoll bar is shown.
    Now move scroll bar left and right and hopefully You will see a problem with buttons :) 

    Is there any solution for that ?
  5. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 14 Mar 2013 Link to this post

    Hi Michal,

    Thank you for writing.

    This behavior is due to the UI virtualization of RadGridView. To avoid such cases you will need a custom column which will use your custom header cell. I have attached a modified version of the example where I have implemented such a column.

    I hope this will be useful. Should you have further questions, I would be glad to assist.

    Greetings,
    Ivan Petrov
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
  6. Michał
    Michał avatar
    2 posts
    Member since:
    Mar 2013

    Posted 14 Mar 2013 Link to this post

    Works Great!!!
    Thank You !:) 
  7. Oliver
    Oliver avatar
    2 posts
    Member since:
    Apr 2012

    Posted 13 Aug 2013 Link to this post

    Hello

    I tried the same thing but with a single dropdown box in the header.
    The thing works so far but when I scroll left right, the selected index of every single dropdown box jumps around. Is there a way to make this work? So that I can select for every header a certain value from a dropdown box (all the boxes have the same choices).
    As I said, I could already get the initialize the dropdown lists. the only problem is the GUI behavior.

    have a nice day
    Oliver Bernhardt

    [EDIT]: Also, some times the header text alignment jumps from MiddleTop to MiddleCenter. 
  8. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 16 Aug 2013 Link to this post

    Hi Francois,

    Thank you for writing.

    The problem you have there has to do with the UI virtualization of RadGridView. When you scroll left and right the visual cells are reused and only the data they display is changed. This requires two components. The first is a UI element that will display the data to the user. You have that in the custom header cell. The second component is the actual data the cell will be displaying. Here is where your implementation needs some improvement. You do not save the selection in the drop down list anywhere. I have attached a sample project where the drop down value is stored in the column's Tag property. This acts as your data component and when you scroll the UI virtualization works properly.

    I hope this will help. Do not hesitate to write back with further questions.

    Regards,
    Ivan Petrov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  9. Oliver
    Oliver avatar
    2 posts
    Member since:
    Apr 2012

    Posted 19 Aug 2013 Link to this post

    Hello

    Thank you very much for your help. It took me some time to adjust your code for my personal needs but it works great now.
    Have a nice day

    Oliver Bernhardt
  10. Adrian
    Adrian avatar
    1 posts
    Member since:
    Jan 2015

    Posted 29 Jan 2015 in reply to Oliver Link to this post

    Hi... I'm interested in this issue... I've downloaded the example... but when I scroll left or right, the dropdowns come back to originial value an I can't keep the right selection on the right column... is there any improved version of this?

    Thanks!
  11. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 03 Feb 2015 Link to this post

    Hi Adrian,

    Thank you for writing.

    Are you sure that you have downloaded the right example project? I have tested with this one and everything is working as expected. 

    I am additionally sending you a gif showing how the grid behaves on my side.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    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.

     
  12. ahmed
    ahmed avatar
    3 posts
    Member since:
    Oct 2015

    Posted 27 Apr in reply to Ivan Petrov Link to this post

    Great solution , but what if i want the custom buttons to fire an event when it clicked ?
  13. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 28 Apr Link to this post

    Hello Ahmed,

    Thank you for writing.

    You create event handler inside the custom header cell element and expose it so that you can subscribe to it. The following KB resource handles a similar scenario in the RadTextBox control: http://www.telerik.com/support/kb/winforms/details/search-box.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  14. ahmed
    ahmed avatar
    3 posts
    Member since:
    Oct 2015

    Posted 05 May in reply to Hristo Merdjanov Link to this post

    Hi Hristo ,

    i tried your idea , but i have a problem now 

    that event handler is null.

     public delegate void ActionButtonsClick(object sender, object action);
      public event ActionButtonsClick OnButtonClicked;

     

      void button1_Click(object sender, EventArgs e)
            {
                if(this.OnButtonClicked!=null)
                {
                    this.OnButtonClicked(sender, "sum");
                }

    }

    and on form1.cs

     void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
            {
                if (e.Column.Name == "Decimal" && e.CellType == typeof(GridHeaderCellElement))
                {
                    e.CellType = typeof(MyHeaderCellElement);
                    (e.CellElement as MyHeaderCellElement).OnButtonClicked += Form1_OnButtonClicked;
                }
            }

    and event not fired any more

    any ideas please ?

  15. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 09 May Link to this post

    Hello Ahmed,

    Thank you for writing back.

    You need to raise the event from within the custom header cell and handle it in your form. I am sending you attached a sample project which should get you going.

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

    Regards,
    Hristo Merdjanov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  16. Aenon
    Aenon avatar
    4 posts
    Member since:
    Jul 2016

    Posted 13 Jul Link to this post

    Hi,

    Is it possible to get the text of the textbox in the gridview from the form? Let's say the textbox has a value, and if I click on one button outside the gridview or press a key combination, I want to copy the value of the textbox in another textbox in the form outside the grid.

    Thanks
  17. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 13 Jul Link to this post

    Hi Aenon,

    Thank you for writing.

    You can accomplish your task by defining a property in the custom HeaderCellElement exposing the RadTextBoxElement. You will also need to store the header cell you create in the form to a variable which can be accessed and via the property and the value of the text box read.

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

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
  18. Aenon
    Aenon avatar
    4 posts
    Member since:
    Jul 2016

    Posted 13 Jul Link to this post

    Thanks, I didn't think on that, I was going in the wrong direction
  19. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 14 Jul Link to this post

    Hi Aenon,

    Thank you for writing back.

    Alternatively, to the suggested approach, you can subscribe to the TextChanged event of the TextBoxElement and raise an event in your form. This way on a form level you will be notified every time the text changes. You can choose the one which suits you best.

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

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready