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

Toggle state of Radiobuttons in RadGridViewColumn

5 Answers 160 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Siingh
Top achievements
Rank 2
Siingh asked on 21 Sep 2010, 09:57 AM
Hi
I have two RadRadiobutton in RadGridViewColumn. now if i select one radiobutton then i want to uncheck second radiobutton which is in second Radgridviewcolumn how do i do this?


Thanks


Kind Regards:
Hariindarr Siingh
McConnell Dowell SEA

5 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 23 Sep 2010, 05:10 PM
Hi Siingh,

Thank you for contacting us. Please review the following KB article. It demonstrates how to handle radio buttons in RadGridView. This help article describes how to access and modify cell values. I hope this helps.

If you have any additional questions, please do not hesitate to ask.

Greetings,
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
Emanuel Varga
Top achievements
Rank 1
answered on 24 Sep 2010, 06:40 AM
Hello Siingh, Jack,

The article Jack is referring to has a few bugs in the latest versions of telerik including missing lines, unable to move columns, column size related problems, i was meaning to submit a modified version to this artice after i had some problems with it but didn't have the time, i will try to add the necessary changes today.

Until then if you consider you don't need a custom column to accomplish what you need you could just set one radio button as the tag to the second, and assign both to the same state changed event.

As soon as I've made those changes i will add them here.

Best Regards,
Emanuel Varga
0
Emanuel Varga
Top achievements
Rank 1
answered on 24 Sep 2010, 08:35 AM
Hello again,

I will add here the extra information i consider to be important in order to have a fully functional custom column.
So, in order for you to be able to change the column position you should create a CustomCell Provider for your column like this:
public class CustomCellProvider : CellElementProvider
   {
       public CustomCellProvider(GridTableElement tableElement)
           : base(tableElement)
       {
       }
 
       public override IVirtualizedElement<GridViewColumn> CreateElement(GridViewColumn data, object context)
       {
           var dataRow = context as GridDataRowElement;
           if (data.Name == "FavouriteColor" && dataRow != null)
           {
               var cell = new RadioButtonCellElement(data, dataRow);
               return cell;
           }
 
           return base.CreateElement(data, context);
       }
 
       public override bool IsCompatible(
           IVirtualizedElement<GridViewColumn> element, GridViewColumn data, object context)
       {
           if (data.Name == "FavouriteColor" &&
               context is GridDataRowElement)
           {
               return element is RadioButtonCellElement;
           }
 
           if (element is RadioButtonCellElement)
           {
               return false;
           }
 
           return base.IsCompatible(element, data, context);
       }
   }

Here the "data.Name" is the name of your column.

After that you have to register for that event like
this.radGridView1.TableElement.CellElementProvider = new CustomCellProvider(this.radGridView1.TableElement);

After that i would suggest some changes inside the arrange override method in order for it to support custom element sizes something like this:
protected override SizeF ArrangeOverride(SizeF finalSize)
       {
           if (this.Children.Count == 3)
           {
               this.Children[0].Arrange(new RectangleF(
                   0,
                   (finalSize.Height / 2) - (this.Children[0].DesiredSize.Height / 2),
                   this.Children[0].DesiredSize.Width,
                   this.Children[0].DesiredSize.Height));
               this.Children[1].Arrange(new RectangleF(
                   this.Children[0].Size.Width,
                   (finalSize.Height / 2) - (this.Children[1].DesiredSize.Height / 2),
                   this.Children[1].DesiredSize.Width,
                   this.Children[1].DesiredSize.Height));
               this.Children[2].Arrange(new RectangleF(
                   this.Children[0].DesiredSize.Width + this.Children[1].DesiredSize.Width,
                   (finalSize.Height / 2) - (this.Children[2].DesiredSize.Height / 2),
                   this.Children[2].DesiredSize.Width,
                   this.Children[2].DesiredSize.Height));
           }
 
           return finalSize;
       }

and finally although it's not mentioned in the article this property is a very important one, because without this, grid lines would not be visible on the custom cell / column:
protected override Type ThemeEffectiveType
{
    get
    {
        return typeof(GridDataCellElement);
    }
}

Hope this helps, if you have any other problems, please do no hesitate to say so.

Best Regards,
Emanuel Varga
0
Siingh
Top achievements
Rank 2
answered on 24 Sep 2010, 08:56 AM
Thanks Emanuel ,Telerik


I am working on it and let you know if any problem.



Thanks



Kind Regards:
Hariindarr Siingh
0
Jack
Telerik team
answered on 24 Sep 2010, 06:15 PM
Hariindarr, If you need further assistance we will be glad to help.

Emanuel, thank you for sharing your solution. I modified the KB according to your suggestions. In addition to the use of cell element provider, you can add custom cells using a custom column. Here is a sample:

public class MyCustomColumn : GridViewDataColumn
{
    public override Type GetCellType(GridViewRowInfo row)
    {
        if (row is GridViewDataRowInfo)
        {
            return typeof(RadioButtonCellElement);
        }
        return base.GetCellType(row);
    }
}

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
Tags
GridView
Asked by
Siingh
Top achievements
Rank 2
Answers by
Jack
Telerik team
Emanuel Varga
Top achievements
Rank 1
Siingh
Top achievements
Rank 2
Share this question
or