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

Data Grid + Radio Button + Single Row

6 Answers 440 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nikhil
Top achievements
Rank 1
Nikhil asked on 13 May 2009, 09:41 PM

Hi
 
First  column of my data grid is a radio Button (used :GridViewDataColumn.CellStyle)..in front of every row in the grid now there is a Radio button

 

 

 

 I want to achive following things using Silverlight DataGrid

1 ) Not let user to select multiple radio buttons,  Currently  user can select more than one radio button

2 ) Select a single row from the data grid having Radio button checked

3 ) Get the Row index of the row for which Radio button is checked
4) Pass the cell content  of another couumn in the selected row

I am not sure how to do this in silverlight and using Telerik data gird

I would highly appreciate if any codesnippet can be provided?  As I am very new to silverlight

A

                <StackPanel Grid.Row="5" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Left" > 
 
                    <twcgv:RadGridView x:Name="RadGridView1" 
                               IsReadOnly="True"    
                               RowIndicatorVisibility="Collapsed"   
                               AutoGenerateColumns="False"   
                               ColumnsWidthMode="Fill" 
                               CanUserFreezeColumns="False"   
                               ScrollMode="RealTime" 
                               UseAlternateRowStyle="True"    
                               MultipleSelect="False" 
                                                                                                          
                               > 
                      
                    <twcgv:RadGridView.Columns > 
               <twcgv:GridViewDataColumn HeaderText="Radio Button" DataType="{x:Null}" > 
                                <twcgv:GridViewDataColumn.CellStyle> 
                                    <Style TargetType="colgrid:GridViewCell">  
                                        <Setter Property="Template">  
                                            <Setter.Value> 
                                                <ControlTemplate TargetType="colgrid:GridViewCell">  
                                                    <Border Margin="0,0,0,0" Padding="10" BorderBrush="DarkGray" BorderThickness="1" 
                                                        CornerRadius="0">  
                                                        <y:RadioButton Name="CellRadioButton"  GroupName="Group1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Checked="RadioButton_Checked" /> 
                                                    </Border> 
                                                </ControlTemplate> 
                                            </Setter.Value> 
                                        </Setter> 
                                    </Style> 
                                </twcgv:GridViewDataColumn.CellStyle> 
                            </twcgv:GridViewDataColumn> 
                                <twcgv:GridViewDataColumn HeaderText="PO#" UniqueName="PONumber"  /> 
                                <twcgv:GridViewDataColumn HeaderText="Vendor Name" UniqueName="VendorName" /> 
                                <twcgv:GridViewDataColumn HeaderText="Description" UniqueName="Description" /> 
                                <twcgv:GridViewDataColumn HeaderText="Requested Date" UniqueName="RequestedDate" /> 
                                <twcgv:GridViewDataColumn HeaderText="Plant Name" UniqueName="PlantName" /> 
                              
                        </twcgv:RadGridView.Columns> 
                             
                   </twcgv:RadGridView> 

6 Answers, 1 is accepted

Sort by
0
Nikhil
Top achievements
Rank 1
answered on 14 May 2009, 02:19 PM
Please help...it's urgent
0
Vlad
Telerik team
answered on 14 May 2009, 03:11 PM
Hello Nikhil,

You can find an example project attached.

Greetings,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Nikhil
Top achievements
Rank 1
answered on 14 May 2009, 09:51 PM
Thansk a lot for the solution ...ot worked fine for me
0
Nikhil
Top achievements
Rank 1
answered on 30 Jul 2009, 09:59 PM
This is really urgent as our Business users are testing the application ...

i asked few days back to suggest me a way to implemente a Radio button col and to provide a solution so that user cannot select multiple radio buttons at one time ........

The solution Was working perfectly till the time we have upgraded top  Silverlight Q2 2009 installer ...now again user can select multiple radio button ...
Followign is code implemented in RADGRIdView1_  Rowloaded event ...which Telerik provided to me in previous POST



 

void RadGridView1_RowLoaded(object sender, RowLoadedEventArgs e)

 

{

 

if (!(e.Row is GridViewNewRow) && !(e.Row is GridViewHeaderRow))

 

{

 

var cell = e.Row.Cells.Where(c => c.Column.UniqueName == "").FirstOrDefault();

 

 

if (cell != null)

 

{

 

var radioButton = cell.ChildrenOfType<RadioButton>().FirstOrDefault();

 

 

if (radioButton != null)

 

{

radioButton.SetBinding(

RadioButton.IsCheckedProperty,

 

 

new Binding("IsSelected") { Source = e.Row.Record, Mode = BindingMode.TwoWay });

 

}

}

}

}

}


GRID .XAML

 

 

 

<StackPanel Grid.Row="6" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,35,0,0" >

 

 

 

 

 

 

<twcgv:RadGridView x:Name="RadGridView1"

 

 

 

 

 

IsReadOnly="True"

 

 

RowIndicatorVisibility="Collapsed"

 

 

AutoGenerateColumns="False"

 

 

CanUserFreezeColumns="False"

 

 

CanUserReorderColumns="False"

 

 

 

 

 

ColumnsWidthMode="None"

 

 

 

 

 

ColumnBackground="white"

 

 

 

 

 

 

ScrollMode="Deferred"

 

 

 

 

 

UseAlternateRowStyle="True"

 

 

MultipleSelect="False"

 

 

 

 

 

FontSize="10"

 

 

MaxWidth="1060"

 

 

 

 

 

MinWidth="1060"

 

 

 

 

 

MinHeight="190"

 

 

 

 

 

MaxHeight="190"

 

 

 

 

 

Margin ="0,-30,0,0"

 

 

 

 

 

Style="{StaticResource BPRadGridViewStyle}"

 

 

RowStyle="{StaticResource RowStyle}"

 

 

AlternateRowStyle="{StaticResource RowStyle_Alternate}"

 

 

 

 

 

DataLoaded="RadGridView1_DataLoaded"

 

 

 

 

 

 

>

 

 

 

 

 

 

<twcgv:RadGridView.Columns >

 

 

 

 

 

 

<twcgv:GridViewColumn UniqueName="">

 

 

 

 

 

 

<twcgv:GridViewColumn.CellTemplate>

 

 

 

 

 

 

<DataTemplate>

 

 

 

 

 

 

<RadioButton Checked="RadioButton_Checked" MaxWidth="20" MinWidth="20" />

 

 

 

 

 

 

</DataTemplate>

 

 

 

 

 

 

</twcgv:GridViewColumn.CellTemplate>

 

 

 

 

 

 

</twcgv:GridViewColumn>

 

 

 

 

 

 

<twcgv:GridViewDataColumn HeaderText="PO#" UniqueName="PONumber" Width="90" />

 

 

 

 

 

 

<twcgv:GridViewDataColumn HeaderText="Vendor Name" UniqueName="VendorName" Width="200" />

 

 

 

 

 

 

<twcgv:GridViewDataColumn HeaderText="Description" UniqueName="MaterialDescription" Width="200" />

 

 

 

 

 

 

<twcgv:GridViewDataColumn HeaderText="Cost Center" UniqueName="CostCenter" Width="120" />

 

 

 

 

 

 

<twcgv:GridViewDataColumn HeaderText="WBS" UniqueName="WBS" Width="90" />

 

 

 

 

 

 

<twcgv:GridViewDataColumn HeaderText="Plant Name" UniqueName="PlantName" Width="200"/>

 

 

 

 

 

 

</twcgv:RadGridView.Columns>

 

 

 

 

 

 

</twcgv:RadGridView>

 

 

 

 

 

 

</StackPanel>

 

0
Nikhil
Top achievements
Rank 1
answered on 30 Jul 2009, 10:00 PM
I would highly appreciate if somebody can look at it as it is really annoying and we need to be very careful before upgrading your new products
0
Vlad
Telerik team
answered on 31 Jul 2009, 07:13 AM
Hi Nikhil,

Here is how to change row loaded to achieve this:

void RadGridView1_RowLoaded(object sender, RowLoadedEventArgs e) 
        { 
            if (!(e.Row is GridViewNewRow) && !(e.Row is GridViewHeaderRow)) 
            { 
                var cell = e.Row.Cells.Where(c => c.Column.UniqueName == "MyColumn").FirstOrDefault(); 
                if (cell != null
                { 
                    var radioButton = cell.ChildrenOfType<RadioButton>().FirstOrDefault(); 
                    if (radioButton != null
                    { 
                        radioButton.Click += delegate(object s, RoutedEventArgs args) 
                        { 
                            RadGridView1.ChildrenOfType<RadioButton>().ToList().ForEach(rb => rb.IsChecked = false); 
                            radioButton.IsChecked = true
                            RadGridView1.SelectedItem = radioButton.DataContext; 
                        }; 
                    } 
                } 
            } 
        } 


Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Nikhil
Top achievements
Rank 1
Answers by
Nikhil
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or