RadioButton column in RadGridView

1 Answer 38 Views
GridView
Carl
Top achievements
Rank 1
Iron
Iron
Iron
Carl asked on 14 Feb 2025, 01:03 AM | edited on 18 Feb 2025, 06:09 PM

I need to add a RadioButton column to my grid and I adapted the code in this demo to do it:

https://docs.telerik.com/devtools/winforms/knowledge-base/creating-a-radradiobuttoncellelement

The difference is I need a single radio button on each row and they need to be mutually exclusive of one another. This part is now working.

Using some sample credit card data, I have 3 challenges that I can't figure out:

1. How can I start the attached project and set the button for the credit card need selected when the form loads?

2. How can I retrieve the selected credit card id value (if any)?

3. I also seem to have a visual bug whereby when I scroll the grid up and down sometimes the button deselects and sometimes it seems to select a second option.

Could you please examine the attached project and let me know what I'm missing?

Thanks

Carl

Carl
Top achievements
Rank 1
Iron
Iron
Iron
commented on 18 Feb 2025, 06:08 PM | edited

Nadya

Thanks for getting back to me..

I like the GridViewSelectColumn feature but we can't use it for 2 reasons: 1. We can't upgrade Telerik at this stage of the QA process and 2. the design team wanted radio buttons and not check boxes since Windows standard is that radio buttons are intended to illustrate mutual exclusivity. That said, I'd like to suggest a new GridViewRadioButtonColumn object that would do just that.

Your advice solved some of my issues. I can set the initial value (#1) and (I think) I have the virtualization issues resolved (#3). My problem is still #2, retrieving the selected credit card id value. In this case, I can't seem to get the buttons to work as a mutually exclusive set. I've attached the latest code in my sample project. Could you please let me know what I'm missing?

Thanks

Carl

Nadya | Tech Support Engineer
Telerik team
commented on 20 Feb 2025, 11:44 AM

Hello, Carl,

I noticed that a support ticket was opened on the same topic after a phone call with our representative. 

Your question has already been addressed in the support ticket ID:1679470. Please see our answer there for more information. You can find it in your Telerik account. 

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 18 Feb 2025, 03:30 PM

Hello, Carl,

The provided project is greatly appreciated.

1. If you need to set a value of specific cell you can access the cell directly and change its Value property.

this.radGridView1.Rows[1].Cells["Selected"].Value = true;

2. To retrieve the selected credit card id value, I suppose that you will need this value everytime when the selection changes.This is why I can suggest to handle the CellValueChanged event and get the credit card id value through GridViewRowInfo:

private void RadGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
    var cardId = e.Row.Cells["CardID"].Value;
    MessageBox.Show(cardId.ToString());
}

3. Such visual glitches while scrolling custom cells may occur since RadGridView uses UI virtualization. You should check carefully the SetContentCore and ensure that only the selected radio button is updated, and prevent others from gaining different toggle state. You can also take a look at the following article where a default cell is used to prevent cell reuse: How to Create Custom Cells with Input Elements - Telerik UI for WinForms

Referring to what you managed to achieve so far, it looks like to me that you need to have only one row selected at a time. I would like that recently we have introduced a GridViewSelectColumn in RadGridView. If you set radGridView1.MultiSelect to false, you will ensure that only a single row will be selected. you can take a look at our select column and consider if it would be suitable for your case or continue utilizing the approach that you have already started with RadiobuttonCellement. I would like to note that the custom cell element is also a valid and correct approach, I just inform you about the new enhancement in case you consider them useful for the case. 

I hope this information is useful. Please let me know if I can assist you further.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Carl
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or