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

Buttons in header (or toolbar)

17 Answers 403 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Francois
Top achievements
Rank 1
Francois asked on 16 Dec 2011, 09:59 PM
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,

17 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 21 Dec 2011, 07:16 AM
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.
0
Michał
Top achievements
Rank 1
answered on 11 Mar 2013, 01:56 PM
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 ?
0
Ivan Petrov
Telerik team
answered on 14 Mar 2013, 11:32 AM
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.
0
Michał
Top achievements
Rank 1
answered on 14 Mar 2013, 02:56 PM
Works Great!!!
Thank You !:) 
0
Oliver
Top achievements
Rank 1
answered on 13 Aug 2013, 11:11 AM
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. 
0
Ivan Petrov
Telerik team
answered on 16 Aug 2013, 09:27 AM
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 >>
0
Oliver
Top achievements
Rank 1
answered on 19 Aug 2013, 02:24 PM
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
0
Adrian
Top achievements
Rank 1
answered on 29 Jan 2015, 08:57 PM
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!
0
Hristo
Telerik team
answered on 03 Feb 2015, 12:05 PM
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.

 
0
ahmed
Top achievements
Rank 1
answered on 27 Apr 2016, 09:13 AM
Great solution , but what if i want the custom buttons to fire an event when it clicked ?
0
Hristo
Telerik team
answered on 28 Apr 2016, 12:19 PM
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.
0
ahmed
Top achievements
Rank 1
answered on 05 May 2016, 02:42 PM

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 ?

0
Hristo
Telerik team
answered on 09 May 2016, 01:48 PM
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.
0
Aenon
Top achievements
Rank 1
answered on 13 Jul 2016, 10:58 AM

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
0
Hristo
Telerik team
answered on 13 Jul 2016, 12:41 PM
Hi ,

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.
0
Aenon
Top achievements
Rank 1
answered on 13 Jul 2016, 02:07 PM
Thanks, I didn't think on that, I was going in the wrong direction
0
Hristo
Telerik team
answered on 14 Jul 2016, 07:57 AM
Hi ,

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.
Tags
GridView
Asked by
Francois
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Michał
Top achievements
Rank 1
Oliver
Top achievements
Rank 1
Adrian
Top achievements
Rank 1
Hristo
Telerik team
ahmed
Top achievements
Rank 1
Aenon
Top achievements
Rank 1
Share this question
or