Hi,
I am using the code from the link http://www.telerik.com/support/kb/winforms/gridview/creating-a-radradiobuttoncellelement.aspx to create a RadRadioButtonElement. Unlike the example provided, I am using just one radiobutton per cell instead of three.
At the row level the RadRadioButtonElement should function like a checkbox. User should be allowed to set the ToggleState to On or Off on a particular row.
Among the rows in the RadGridView, there cannot be more than one row which has this column's ToggleState set to On.
Please check the attached image to get an idea.
I am using the code from the link http://www.telerik.com/support/kb/winforms/gridview/creating-a-radradiobuttoncellelement.aspx to create a RadRadioButtonElement. Unlike the example provided, I am using just one radiobutton per cell instead of three.
At the row level the RadRadioButtonElement should function like a checkbox. User should be allowed to set the ToggleState to On or Off on a particular row.
Among the rows in the RadGridView, there cannot be more than one row which has this column's ToggleState set to On.
Please check the attached image to get an idea.
12 Answers, 1 is accepted
0
Hello Jack, I modified the KB article to make it suitable for your case. Please check the attached file and tell whether it helps.
Should you have any further questions, we will be glad to help.
Greetings, Svett
the Telerik team
Should you have any further questions, we will be glad to help.
Greetings, Svett
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Jack
Top achievements
Rank 1
answered on 14 Apr 2011, 03:12 PM
Hi Svett,
Thanks for the modification and it does work. But the other functionality which I need is to be able to set the ToggleState to Off when a user clicks on a cell which is already set to "On" similar to a checkbox functionality.
Following is the code change I made in the mousedown event. I am trying to set the Value to zero for the current cell if it's already checked but it's not working. It's checking it back again.
Thanks for the modification and it does work. But the other functionality which I need is to be able to set the ToggleState to Off when a user clicks on a cell which is already set to "On" similar to a checkbox functionality.
Following is the code change I made in the mousedown event. I am trying to set the Value to zero for the current cell if it's already checked but it's not working. It's checking it back again.
private void radioButtonElement1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.Value = 1;
foreach (GridViewRowInfo row in this.ViewTemplate.Rows)
{
if (row != this.RowInfo)
{
row.Cells[this.ColumnInfo.Name].Value = 0;
}
else
{
//If current cell is already checked, uncheck it.
if (Convert.ToInt32(this.RowInfo.Cells[this.ColumnInfo.Name].Value) == 1)
{
row.Cells[this.ColumnInfo.Name].Value = 0;
}
}
}
}
0
Accepted
Hello Jack,
Svett
the Telerik team
I am enclosing a modified version that implements the desired scenario.
Greetings,Svett
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jack
Top achievements
Rank 1
answered on 19 Apr 2011, 11:32 PM
Hi Svett,
It just worked perfectly.
Thanks again for your help.
It just worked perfectly.
Thanks again for your help.
0
Jack
Top achievements
Rank 1
answered on 20 Apr 2011, 08:34 PM
Hi Svett,
I came across a problem wherein I am unable to remove a selected row from the RadGridView. This error can be reproduced only if the value in the RadioButtonColumn (of the selected row) is toggled.
ArgumentException:
Message: Cannot remove objects not in the list.
Stack Trace:
at System.Data.DataView.System.Collections.IList.Remove(Object value)
at Telerik.WinControls.Data.RadListSource`1.RemoveAt(Int32 index)
at Telerik.WinControls.UI.GridViewRowCollection.RemoveAt(Int32 index, Boolean selectCurrentRow)
at Telerik.WinControls.UI.GridViewRowCollection.Remove(GridViewRowInfo item, Boolean selectCurrentRow)
at Telerik.WinControls.UI.GridViewRowCollection.Remove(GridViewRowInfo item)
at DocMinder5.frmNewEdit3.DeleteSelectedDocument() in C:\Projects\DocMinder 5 Development\WordTech DocMinder 5\DocMinder 5\frmNewEdit3.cs:line 2102
Please advise.
I came across a problem wherein I am unable to remove a selected row from the RadGridView. This error can be reproduced only if the value in the RadioButtonColumn (of the selected row) is toggled.
rgvDocuments.Rows.Remove(rgvDocuments.SelectedRows[0]);
ArgumentException:
Message: Cannot remove objects not in the list.
Stack Trace:
at System.Data.DataView.System.Collections.IList.Remove(Object value)
at Telerik.WinControls.Data.RadListSource`1.RemoveAt(Int32 index)
at Telerik.WinControls.UI.GridViewRowCollection.RemoveAt(Int32 index, Boolean selectCurrentRow)
at Telerik.WinControls.UI.GridViewRowCollection.Remove(GridViewRowInfo item, Boolean selectCurrentRow)
at Telerik.WinControls.UI.GridViewRowCollection.Remove(GridViewRowInfo item)
at DocMinder5.frmNewEdit3.DeleteSelectedDocument() in C:\Projects\DocMinder 5 Development\WordTech DocMinder 5\DocMinder 5\frmNewEdit3.cs:line 2102
Please advise.
0
Accepted
Hi Jack,
This issue appears, because the row was modified and the editing operation is still not finished. You can finish the operation by calling the EndCurrentEdit method of the currency manager. I modified your code the following way:
I hope this helps.
All the best,
Jack
the Telerik team
This issue appears, because the row was modified and the editing operation is still not finished. You can finish the operation by calling the EndCurrentEdit method of the currency manager. I modified your code the following way:
private
void
button1_Click(
object
sender, EventArgs e)
{
if
(
this
.radGridView1.SelectedRows.Count > 0)
{
ICurrencyManagerProvider currencyManagerProvider =
this
.radGridView1.MasterTemplate.ListSource
as
ICurrencyManagerProvider;
currencyManagerProvider.CurrencyManager.EndCurrentEdit();
this
.radGridView1.Rows.Remove(
this
.radGridView1.SelectedRows[0]);
}
}
I hope this helps.
All the best,
Jack
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jack
Top achievements
Rank 1
answered on 25 Apr 2011, 08:18 PM
Thanks for your help Jack. It did work.
0
Martin Lundgard
Top achievements
Rank 2
answered on 30 Nov 2011, 11:10 AM
This is exactly what I'm looking for and working smooth. But, is there any way to get the radiobutton to honour the textalign property on the column? Maybe extending the ArrangeOverride code a little?
0
Hi Arve Asheim,
Yes, your assumption is correct. In this case you should change the ArrangeOverride method the following way:
Then you can change the TextAlignment property of GridRadioButtonElement when handling the CreateChildElements method:
I hope this helps. Should you have any further questions, do not hesitate to write back.
Greetings,
Jack
the Telerik team
Yes, your assumption is correct. In this case you should change the ArrangeOverride method the following way:
protected
override
SizeF ArrangeOverride(SizeF finalSize)
{
if
(
this
.Children.Count == 1)
{
RectangleF clientRect = GetClientRectangle(finalSize);
this
.Children[0].Arrange(
new
RectangleF(
0,
(finalSize.Height / 2) - (
this
.Children[0].DesiredSize.Height / 2),
clientRect.Width,
this
.Children[0].DesiredSize.Height));
}
return
finalSize;
}
Then you can change the TextAlignment property of GridRadioButtonElement when handling the CreateChildElements method:
radioButtonElement1.TextAlignment = ContentAlignment.MiddleRight;
I hope this helps. Should you have any further questions, do not hesitate to write back.
Greetings,
Jack
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Mark
Top achievements
Rank 1
answered on 19 Jun 2014, 11:08 AM
Hi,
I have implemented the radio button column as specified in the RadRadioButtonCellElementCS-Modified.zip project. It works fine until I add child templates in unbound mode, when I select a different row and then select the radio button on that row, the previous radio button is not deselected. See attached screenshot. How can I resolve this.
Thanks,
Simon Davies.
I have implemented the radio button column as specified in the RadRadioButtonCellElementCS-Modified.zip project. It works fine until I add child templates in unbound mode, when I select a different row and then select the radio button on that row, the previous radio button is not deselected. See attached screenshot. How can I resolve this.
Thanks,
Simon Davies.
0
Mark
Top achievements
Rank 1
answered on 19 Jun 2014, 12:26 PM
I have found a solution to this. If I add BeginEdit() and EndEdit() for the cells in which the check is changing, the grid gets updated correctly e.g.
private void radioButtonElement1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.Value = 1;
foreach (GridViewRowInfo row in this.ViewTemplate.Rows)
{
if (row != this.RowInfo)
{
row.Cells[this.ColumnInfo.Name].BeginEdit();
row.Cells[this.ColumnInfo.Name].Value = 0;
row.Cells[this.ColumnInfo.Name].EndEdit();
}
}
}
private void radioButtonElement1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.Value = 1;
foreach (GridViewRowInfo row in this.ViewTemplate.Rows)
{
if (row != this.RowInfo)
{
row.Cells[this.ColumnInfo.Name].BeginEdit();
row.Cells[this.ColumnInfo.Name].Value = 0;
row.Cells[this.ColumnInfo.Name].EndEdit();
}
}
}
0
Hello Jack,
Thank you for writing.
It would be better if you enclose the iteration within Begin/End update block. This will improve the performance in case you have many rows and will update the values:
If you have any questions, please do not hesitate to contact us.
Regards,
Dimitar
Telerik
Thank you for writing.
It would be better if you enclose the iteration within Begin/End update block. This will improve the performance in case you have many rows and will update the values:
private
void
radioButtonElement1_MouseDown(
object
sender, System.Windows.Forms.MouseEventArgs e)
{
this
.Value = 1;
this
.ViewTemplate.BeginUpdate();
foreach
(GridViewRowInfo row
in
this
.ViewTemplate.Rows)
{
if
(row !=
this
.RowInfo)
{
row.Cells[
this
.ColumnInfo.Name].Value = 0;
}
}
this
.ViewTemplate.EndUpdate();
}
If you have any questions, please do not hesitate to contact us.
Regards,
Dimitar
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.