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

Checkbox Inside Gridview is not saving its state

4 Answers 108 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sameh
Top achievements
Rank 1
Sameh asked on 17 Jun 2009, 06:36 AM
Dear Sir,
I have an application which  loading UserControl Dynamically with code, inside the UserControl I have a RadGrdivView which contains a Checkbox Column, theis is the code i have:
Window:
-----

<Window x:Class="Window2"

 

 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

 

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

 

Title="Window2" Height="300" Width="300" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">

 

 

 

<Grid>

 

 

 

<telerik:RadTabControl Name="RadTabControl1">

 

 

 

<telerik:RadTabItem Header="Tab1" Name="tb1">

 

 

 

 

</telerik:RadTabItem>

 

 

 

<telerik:RadTabItem Header="Tab2" Name="tb2">

 

 

 

</telerik:RadTabItem>

 

 

 

</telerik:RadTabControl>

 

 

 

</Grid>

 

</

 

Window>




 

Partial Public Class Window2

 

 

Private Sub Window2_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded

 

 

Dim db As New TeachersDataContext

 

 

Dim Te = (From t In db.Teachers Select t).ToList

 

 

 

For Each itm As Telerik.Windows.Controls.RadTabItem In RadTabControl1.Items

 

 

Dim uc As New UserControl1

 

uc.ds = Te

uc.SetDG()

itm.Content = uc

 

Next

 

 

 

 

 

End Sub

 

End

 

Class



UserControl:
----

<

 

UserControl x:Class="UserControl1"

 

 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

 

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

 

xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">

 

 

 

<Grid>

 

 

 

 

<telerik:RadGridView Name="gvTeachers" telerik:StyleManager.Theme="Summer" AutoGenerateColumns="False" RowIndicatorVisibility="Collapsed" IsReadOnly="True" ShowGroupPanel="False">

 

 

 

<telerik:RadGridView.Columns>

 

 

 

<telerik:GridViewDataColumn Width="Auto">

 

 

 

<telerik:GridViewColumn.CellTemplate>

 

 

 

<DataTemplate>

 

 

 

<CheckBox Name="chkIs_Selected" Margin="3" IsChecked="True" ></CheckBox>

 

 

 

</DataTemplate>

 

 

 

</telerik:GridViewColumn.CellTemplate>

 

 

 

</telerik:GridViewDataColumn>

 

 

 

<telerik:GridViewDataColumn HeaderText="Teacher Name" HeaderTextAlignment="Center" Width="*">

 

 

 

<telerik:GridViewColumn.CellTemplate>

 

 

 

<DataTemplate>

 

 

 

<TextBlock Text="{Binding Teacher_Full_Name}"></TextBlock>

 

 

 

</DataTemplate>

 

 

 

</telerik:GridViewColumn.CellTemplate>

 

 

 

</telerik:GridViewDataColumn>

 

 

 

</telerik:RadGridView.Columns>

 

 

 

</telerik:RadGridView>

 

 

 

 

</Grid>

 

</

 

UserControl>

 



Partial

 

Public Class UserControl1

 

 

Private _ds As List(Of Teacher)

 

 

Public Property ds() As List(Of Teacher)

 

 

Get

 

 

Return _ds

 

 

End Get

 

 

Set(ByVal value As List(Of Teacher))

 

_ds = value

 

End Set

 

 

End Property

 

 

Public Sub SetDG()

 

gvTeachers.ItemsSource = _ds

 

End Sub

 

End

 

Class

 



The problem i have is:
when i run the application all the checkboxes is checked (which is the default state) but when i uncheck some of them and then swich to another tab all the checkboxes is returning to its original state (Checked).
I tried to simulate this issue without loading the UserControls at runtime (I put two RadGridVIews in the TabControl) and everyting is running OK,
Why this happing and if there is any way to solve this please tell me.

Thank you





 

 


 

 

 



UserControl
--------------

 

4 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 17 Jun 2009, 12:15 PM
Hello Sameh,

You will have to bind the IsChecked property of your check-box to something in your data item to preserve its state. Otherwise, when the grid rows are recreated (tabbing) each check-box will be created from scratch and will be checked as defined in the template.

If this does not make sense or it cannot be implemented for your scenario, please tell us what is the exact goal that you are after and we will try to think of a solution.

Kind regards,
Ross
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
Sameh
Top achievements
Rank 1
answered on 17 Jun 2009, 12:30 PM
Thank you for your reply,
Here is my scenario:
I am preparing a program for a school and i have a (Classes table & Teachers table),
here in this window i want to assign the teachers to the classes, so I am reading the classes table and generating the Tabs regarding to the classes (each class will be represented by a TabItem).
the content of each TabItem will be the UserControl which contains the Teachers Grid, each row in the teachers grid will have a checkbox, then the user will check the Teachers for each class and click save (this will save the all).
0
Rossen Hristov
Telerik team
answered on 18 Jun 2009, 12:40 PM
Hi Sameh,

I see. Then you should bind the Checkbox to the boolean property that indicates whether a teacher is assigned to class. This will preserve the information between tabbing in and out of a grid. The thing is that each time you switch tabs -- the grid rows are recreated and if you do not update a data source, your changes will be lost. By the way, you can call your "Save" logic automatically between switching tabs. This should help.

Please, do not hesitate to drop me a line if you have any other questions.

Regards,
Ross
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
Sameh
Top achievements
Rank 1
answered on 18 Jun 2009, 02:20 PM
Dear Sir,
Thank you very much,
I think that if I called the save logic on swiching tabs this will make a conflict for the end user, so i think that i have to put a save button in each of the tabs and the user will save it one by one.
Tags
GridView
Asked by
Sameh
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Sameh
Top achievements
Rank 1
Share this question
or