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

loop through gridview

7 Answers 298 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sameh
Top achievements
Rank 1
Sameh asked on 27 May 2009, 07:20 AM
Dear Sir,
I have an application with RadGridView and a button, on of the columns of the Grid contains a check box (not binding to any data).
i want to loop through all the rows of the grid on the button click event and check of the check box is check and show a message with a field of the data in the same row, please tell me how to do this.

thank you

7 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 27 May 2009, 07:50 AM
Hi Sameh,

You can find small example attached.

All the best,
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
Sameh
Top achievements
Rank 1
answered on 27 May 2009, 09:51 AM
Thank you very much,
actualy I am using VB.NET, and I tried to write the same code in VB.NET and I got an error (below is my button click event):



        Dim GridRows As IList(Of GridViewRow) = RadGridView1.ChildrenOfType(Of GridViewRow)()

        For Each r As GridViewRow In GridRows

            If Not (TypeOf r Is GridViewNewRow) AndAlso Not (TypeOf r Is GridViewHeaderRow) Then

                ' MessageBox.Show(CType(r.FindName("chk"), CheckBox).IsChecked.ToString)

            End If

        Next

the error location is yellow highlited, the error message is: (Expression of type 'Telerik.Windows.Controls.GridView.GridViewRow' can never be of type 'Telerik.Windows.Controls.GridView.GridViewHeaderRow')

can you please tell me if i have a problem somewhere.

also when i tried to write the XAML file as in your example i got an error also (yellow highlited)

<telerik:GridViewColumn>

                    <telerik:GridViewColumn.CellTemplate>

                        <DataTemplate>

                            <CheckBox />

                        </DataTemplate>

                    </telerik:GridViewColumn.CellTemplate>

                </telerik:GridViewColumn>

the error message is: the attached property CellTemplate was not found in type GridViewColumn, so i wrote the XAML like this:

 

 

<telerik:GridViewDataColumn HeaderText="check me" Width="Auto">

 

 

 

<telerik:GridViewColumn.CellStyle>

 

 

 

<Style TargetType="telerik:GridViewCell">

 

 

 

<Setter Property="Template">

 

 

 

<Setter.Value>

 

 

 

<ControlTemplate TargetType="telerik:GridViewCell">

 

 

 

<CheckBox Name="chk"></CheckBox>

 

 

 

</ControlTemplate>

 

 

 

</Setter.Value>

 

 

 

</Setter>

 

 

 

</Style>

 

 

 

</telerik:GridViewColumn.CellStyle>

 

 

 

</telerik:GridViewDataColumn>

 



it is working now but can you please tell me what is the problem in the previous code.

Thank you






 

0
Vlad
Telerik team
answered on 27 May 2009, 10:48 AM
Hi Sameh,

Do you have our latest version? CellTemplate is available since Q1 2009.

Regards,
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
Sameh
Top achievements
Rank 1
answered on 27 May 2009, 11:16 AM
this is the version i have: 2009.1.312.35,
I removed the references from my project and added a refrences to the DLL files from your projects and it is worked (the XAML file only) but the code behind error (VB.NET error) is still.
0
Accepted
Vlad
Telerik team
answered on 28 May 2009, 07:37 AM
Hello Sameh,

My mistake! You can remove GridViewHeaderRow check.

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
Sajjad Shah
Top achievements
Rank 1
answered on 12 Nov 2010, 11:21 PM
Can this happen in silvelight RadGridView? I also want to loop throught the grid rows and wanted to update ceratin control in the cell of the row.?? Very urgent and Important for me.
0
Milan
Telerik team
answered on 15 Nov 2010, 08:25 AM
Hi Sajjad Shah,

The best approach is to loop through all data item and update their properties. If the data object implement INotifyPropertyChanged, and they should, the UI will be updated automatically.

You can easily loop through all items using RadGridView's Items property:

foreach (var item in this.playersGrid.Items)
{
    var mydataItem = item as MyDataItemType;
  
    mydataItem.Property1 = "NewValue";
}


Greetings,
Milan
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
Sameh
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Sameh
Top achievements
Rank 1
Sajjad Shah
Top achievements
Rank 1
Milan
Telerik team
Share this question
or