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

Radiobutton inside a dynamic RadGridView

2 Answers 441 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Serena
Top achievements
Rank 1
Serena asked on 16 Mar 2017, 12:48 PM

Hi,

I have some problems in building a radGridView with radiobutton inside in XAML. You can see the attached image to have an idea of what I'm doing.

I have a grid that contains a list of "container" (they could be one, 2 or more). So every row has a plate(with an id) and 2 radio button (ground - Upper). I retrieve the value of these radiobutton from the DB. Radio button Ground is selected when the variable IsUtiInDoubleStakerHold == 0. If IsUtiInDoubleStakerHold == 1radiobutton Upper has to be selected; if radiobutton Ground is selected, radiobutton Upper cannot be selected and vice versa. For every row I need to select a radio button, and then I have to save the value eventually modified. How can I do this? Actually with this code if I do a choice of a value in the first row, then when I make a selection on the second row, I lost the value of the radiobutton selected in the first row (I can't see anymore the selection done before).

How can i solve this problem? 

After that, how can I maintain the value changed in every row? (I hope to save everything in the object  public ObservableCollection<ItuForYard> ItusSameGroupList)

The xaml RadGridView is defined in this way:

01.<StackPanel Grid.Row="3" >
02.<telerik:RadGridView
03.     SelectedItem="{Binding SelectedItu, Mode=TwoWay}"
04.      ShowColumnSortIndexes="False"
05.          ItemsSource="{Binding ItusSameGroupList, Mode=TwoWay}"                           
06.      Visibility="{Binding GridItusSameGroupVisibility}"
07.       Margin="0,10,0,10" >
08.  <telerik:RadGridView.Columns>
09.       <telerik:GridViewDataColumn t:I18N.Translate="ITU Id"
                                            DataMemberBinding="{Binding UtiId}" Width="0" IsVisible="False" />
10.       <telerik:GridViewDataColumn t:I18N.Translate="ITU Plate"
                                            DataMemberBinding="{Binding UtiPlate}"       Width="4*" />
11.      <telerik:GridViewDataColumn t:I18N.Translate="Ground" Width="3*">
12.         <telerik:GridViewDataColumn.CellTemplate>
13.             <DataTemplate>
14.                <RadioButton GroupName="GroundUpper" Content="{Binding RadioButtonGround}"  
               HorizontalAlignment="Center"
IsChecked="{Binding RadioButtonGroundIsChecked,                                                                           Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                IsEnabled="{Binding IsGroundUpperRadioButtonEnabled}" />
18.             </DataTemplate>
19.        </telerik:GridViewDataColumn.CellTemplate>
20.     </telerik:GridViewDataColumn>
21.     <telerik:GridViewDataColumn t:I18N.Translate="Upper"
                                DataMemberBinding="{Binding IsUtiInDoubleStakerHold}" Width="3*">
22.       <telerik:GridViewDataColumn.CellTemplate>
23.          <DataTemplate>
24.             <RadioButton GroupName="GroundUpper" Content="{Binding RadioButtonUpper}"
25.         HorizontalAlignment="Center"
26.          IsChecked="{Binding RadioButtonUpperIsChecked, Mode=TwoWay,    
               UpdateSourceTrigger=PropertyChanged}"
27.          IsEnabled="{Binding IsGroundUpperRadioButtonEnabled}" />
28.          </DataTemplate>
29.      </telerik:GridViewDataColumn.CellTemplate>
30.    </telerik:GridViewDataColumn>
31.  </telerik:RadGridView.Columns>
32.</telerik:RadGridView>
33.</StackPanel>

 

In the cs file:

public bool IsGroundUpperRadioButtonEnabled => SelectedItu != null &&
                                                        SelectedItu.IsUtiInDoubleStakerHold != 2;
        public Visibility GridItusSameGroupVisibility => SelectedItu != null ? Visibility.Visible : Visibility.Collapsed;
        public bool RadioButtonGroundIsChecked => SelectedItu != null && SelectedItu.IsUtiInDoubleStakerHold == 0;
        public bool RadioButtonUpperIsChecked => SelectedItu != null && SelectedItu.IsUtiInDoubleStakerHold == 1;

 public ObservableCollection<ItuForYard> ItusSameGroupList { get; set; } = new ObservableCollection<ItuForYard>();

 

Then I populate the list of container with the result from the DB

 ItusSameGroupList = new ObservableCollection<ItuForYard>(ituResponse.Result);

2 Answers, 1 is accepted

Sort by
0
Federico
Top achievements
Rank 1
answered on 16 Mar 2017, 02:19 PM

Hi Serena,

I'm the master of "stratagemmi".

I'm confident you can solve this by putting a variable for each row in both of the radiobutton GroupName property in order to keep the radiobutton group separate from each row. 

I guess you can use for example the binding with some id like "{Binding UtiId}".

Let us know, we want all hear from you that you have resolved it.

0
Stefan Nenchev
Telerik team
answered on 21 Mar 2017, 08:11 AM
Hi Serena, Federico,

Let me suggest an alternative approach that might be useful. Since you want to store the values in two different fields, you can work with the setters of the objects and when one of the properties is set to true to set the other one to false and vice versa. Please have a look at the attached sample as it should be a viable approach in your situation.

Have a great rest of the week.

Regards,
Stefan Nenchev
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Serena
Top achievements
Rank 1
Answers by
Federico
Top achievements
Rank 1
Stefan Nenchev
Telerik team
Share this question
or