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
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?
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.
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
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.
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);
};
Sorry, I meant to do it the 1st link way not the 2nd link.
Apparently this works:
e.CellElement.Children.Clear();
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