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

RadGirdview and cell buttons

8 Answers 371 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deasun
Top achievements
Rank 3
Iron
Iron
Iron
Deasun asked on 10 Jun 2019, 04:05 PM

Two questions:

1] How to make a column cells look like and act like buttons?

2] How to then capture when the user clicks on the button in the cell?

 

In my old code I would have something like:

.Columns("Do It").Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button

Looking for the equivilent to that and then how to capture the click event.

 

Thanks

Deasun.

8 Answers, 1 is accepted

Sort by
0
Deasun
Top achievements
Rank 3
Iron
Iron
Iron
answered on 10 Jun 2019, 06:40 PM

Well I thought I had it.

I found: radGrid1_CellFormatting

and added the following to it:

if (e.CellElement.ColumnInfo.Name == "Do It" )
                            {
                                // adding a new button element
                                var element = new RadButtonElement();
                                element.Margin = new Padding(0, 0, 0, 0);
                                element.ImageAlignment = ContentAlignment.MiddleCenter;
                                element.Alignment = ContentAlignment.MiddleCenter;
                                element.Text = e.CellElement.Value.ToString();
                                e.CellElement.Children.Add(element);
                            }
                            else
                            {
                                
                            };

Problem I just noticed now is when you move the scrollbars of the grid some of the other columns have their cells changed to buttons!

Not really sure why, guessing something to do with the virtualization of the grid.

Seems to be completely random.

help?

 

0
Deasun
Top achievements
Rank 3
Iron
Iron
Iron
answered on 10 Jun 2019, 08:01 PM

from reading it appears I need to reset the other columns cells!

somethign like: e.CellElement.ResetValue(LightVisualElement.ChildElementAddedEvent, ValueResetFlags.DefaultValueOverride);

but what would it be? that dont work.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 Jun 2019, 08:40 AM
Hello, Deasun,        

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. Additional information how to properly use the CellFormatting event is available in the following help article: https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formatting-cells

However, I would like to note that RadGridView offers a GridViewCommandColumn which is suitable for your case. It displays a button element that responds to user input mouse clicks and keyboard key presses. Either mouse click or keyboard input fires the CommandCommandCellClick event. Please refer to the online documentation: https://docs.telerik.com/devtools/winforms/controls/gridview/columns/column-types/gridviewcommandcolumn
 
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
Deasun
Top achievements
Rank 3
Iron
Iron
Iron
answered on 11 Jun 2019, 11:42 AM

Thanks for the reply.

Will read both those links.

? is it possible to turn off that UI virtualization on the controls.

Think I ran into a similar issue with the DDL control.

0
Deasun
Top achievements
Rank 3
Iron
Iron
Iron
answered on 11 Jun 2019, 12:06 PM

If I wanted to do it the 2nd link way, what do I need to put in the reset line?

e.CellElement.ResetValue(LightVisualElement.ChildElementAddedEvent, ValueResetFlags.DefaultValueOverride);

Not sure what should be here for my situation:

LightVisualElement.ChildElementAddedEvent

and

ValueResetFlags.DefaultValueOverride

 

if (e.CellElement.ColumnInfo.Name == "Do It")
                            {
                                // adding a new button element
                                var element = new RadButtonElement();
                                element.Margin = new Padding(0, 0, 0, 0);
                                element.ImageAlignment = ContentAlignment.MiddleCenter;
                                element.Alignment = ContentAlignment.MiddleCenter;
                                element.Text = e.CellElement.Value.ToString();
                                e.CellElement.Children.Add(element);

                                // or setting an image to the current element
                                //e.CellElement.Image = Properties.Resources.FilterImage;
                            }
                            else
                            {
                                e.CellElement.ResetValue(LightVisualElement.ChildElementAddedEvent, ValueResetFlags.DefaultValueOverride);
                            };

0
Deasun
Top achievements
Rank 3
Iron
Iron
Iron
answered on 11 Jun 2019, 12:15 PM

Sorry, I meant to do it the 1st link way not the 2nd link.

 

0
Deasun
Top achievements
Rank 3
Iron
Iron
Iron
answered on 11 Jun 2019, 12:35 PM

Apparently this works:

e.CellElement.Children.Clear();

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Jun 2019, 09:21 AM
Hello, Deasun,        

The purpose of the UI virtualization in RadGridView is to optimize performance. It is integrated in the core functionality of RadGridView and can't be turned off.

RadDropDownList also uses virtualization and if you customize the visual elements, make sure that applied style is reset for the rest of the visual items. Additional information on this topic is available in the following help article: https://docs.telerik.com/devtools/winforms/controls/dropdown-listcontrol-and-checkeddropdownlist/dropdownlist/customizing-appearance/formatting-items

Instead of clearing the whole Children collection of the CellElement, find the RadButtonElement that you insert and simply remove it from the CellElement.Children collection.

However, I would like to recommend you once again to use the GridViewCommandColumn. It provides a similar functionality out-of-the-box and you don't need to add/remove the button element: https://docs.telerik.com/devtools/winforms/controls/gridview/columns/column-types/gridviewcommandcolumn

Should you have further questions please let me know.

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.
Tags
GridView
Asked by
Deasun
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Deasun
Top achievements
Rank 3
Iron
Iron
Iron
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or