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

Checkbox in gridview

1 Answer 207 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chetan
Top achievements
Rank 1
Chetan asked on 20 Jul 2010, 02:24 PM
Hi,
I am using telerik gridview control. I need to add checkboxes in all cells. When user clicks on the save button i need to know all checked checkboxes with column and row the selected checkbox is present.
Here is the code that i am using.

<grid:RadGridView x:Name="gridview" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4"  RowIndicatorVisibility="Collapsed" IsReadOnly="True" AutoGenerateColumns="False" CanUserFreezeColumns="False"  CanUserResizeColumns="False" Width="700">
              
            <grid:RadGridView.Columns>
                <grid:GridViewDataColumn x:Name="hCol"  Header="#" HeaderTextAlignment="Center"  Width="150" TextAlignment="Center" IsSortable="False"/>
                <!--<grid:GridViewDataColumn x:Name="hColumn" Header="Heading"  HeaderTextAlignment="Center" Width="200">
                    <grid:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <telerikInput:RadComboBox x:Name="cbM" SelectedIndex="0" >
                            </telerikInput:RadComboBox>
                        </DataTemplate>
                    </grid:GridViewDataColumn.CellTemplate>
                </grid:GridViewDataColumn>-->
                <!--<grid:GridViewDataColumn x:Name="cbG1" Header="G-1"  HeaderTextAlignment="Center" Width="50">
                    <grid:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox x:Name="chkMeasures" />
                        </DataTemplate>
                    </grid:GridViewDataColumn.CellTemplate>
                </grid:GridViewDataColumn>-->
                <grid:GridViewDataColumn x:Name="cbG1"  Header="G-1" IsSortable="False" TextAlignment="Center" HeaderTextAlignment="Center">
                    <grid:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="false" Click="CheckBox_Click" />
                        </DataTemplate>
                    </grid:GridViewDataColumn.CellTemplate>
                </grid:GridViewDataColumn>
                  
                <grid:GridViewDataColumn x:Name="cbG2"  Header="G-2" IsSortable="False" TextAlignment="Center" HeaderTextAlignment="Center">
                    <grid:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="false" Checked="CbChecked_Click"/>
                        </DataTemplate>
                    </grid:GridViewDataColumn.CellTemplate>
                </grid:GridViewDataColumn>
                  




                <grid:GridViewDataColumn x:Name="cbG3"  Header="G-3" IsSortable="False" HeaderTextAlignment="Center">
                    <grid:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="false"/>
                        </DataTemplate>
                    </grid:GridViewDataColumn.CellTemplate>
                </grid:GridViewDataColumn>
                  
                <grid:GridViewDataColumn x:Name="cbG4"  Header="G-4" IsSortable="False" HeaderTextAlignment="Center">
                    <grid:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="false"/>
                        </DataTemplate>
                    </grid:GridViewDataColumn.CellTemplate>
                </grid:GridViewDataColumn>
                  
                <grid:GridViewDataColumn x:Name="cbG5"  Header="G-5" IsSortable="False" HeaderTextAlignment="Center">
                    <grid:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="false"/>
                        </DataTemplate>
                    </grid:GridViewDataColumn.CellTemplate>
                </grid:GridViewDataColumn>
                  
                <grid:GridViewDataColumn x:Name="cbG6"  Header="G-6" IsSortable="False" HeaderTextAlignment="Center">
                    <grid:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="false"/>
                        </DataTemplate>
                    </grid:GridViewDataColumn.CellTemplate>
                </grid:GridViewDataColumn>
                  
                <grid:GridViewDataColumn x:Name="cbG7"  Header="G-7" IsSortable="False" HeaderTextAlignment="Center">
                    <grid:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="false"/>
                        </DataTemplate>
                    </grid:GridViewDataColumn.CellTemplate>
                </grid:GridViewDataColumn>
                  
                <grid:GridViewDataColumn x:Name="cbG8"  Header="G-8" IsSortable="False" HeaderTextAlignment="Center">
                    <grid:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="false"/>
                        </DataTemplate>
                    </grid:GridViewDataColumn.CellTemplate>
  
                      
  
                </grid:GridViewDataColumn>
                <!--<grid:GridViewCheckBoxColumn Header="Check box">
                    <grid:GridViewCheckBoxColumn.CellTemplate>
                          
                            <CheckBox IsChecked="false"/>
                          
                    </grid:GridViewCheckBoxColumn.CellTemplate>
                </grid:GridViewCheckBoxColumn>-->
            </grid:RadGridView.Columns>
            </grid:RadGridView>

Thank you
Chetan

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 23 Jul 2010, 10:43 AM
Hi Chetan,

Please provide us with more details about the purpose of your project. According to the code-snippet you have sent, it seems that it would be a good idea - if possible in your case - to bind the CheckBox-es to specific properties of the underlaying data. Thus as soon as the a certain CheckBox is checked, the data will be updated. Afterwards, you will be able to walk around the items and find the properties that have been set to "True" - meaning the corresponding CheckBox is checked.
In case this solution is not appropriate for you scenario, you should keep in mind that when the rows and columns are not visible, you cannot examine the values in the cells unless you turn off the Virtualization with the properties of the grid EnableColumnVirtualizaiton and EnableRowVirtualization. However, this will lead to slower performance in case of many rows and columns.
 

Kind regards,
Maya
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
Chetan
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or