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

Get the Gridview current row

2 Answers 472 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael Luna
Top achievements
Rank 1
Michael Luna asked on 10 Jan 2011, 11:01 AM
I have a button in a cell in each row.
When the user clicks the button, I need to transfer data from that row some where else

xaml

      <telerik:RadGridView  x:Name="Search_RadDG" Margin="5,0"
                            ItemsSource="{Binding SearchResults}"
                            SelectionUnit="FullRow"
                             >

        <telerik:RadGridView.Columns>
          <telerik:GridViewColumn Header="Add Candidate" >
            <telerik:GridViewColumn.CellTemplate>
              <DataTemplate>
                <telerik:RadButton Content="Add" Click="RadButton_Click" />
              </DataTemplate>
            </telerik:GridViewColumn.CellTemplate>
          </telerik:GridViewColumn>
        </telerik:RadGridView.Columns>

      </telerik:RadGridView>

VB

 Dim btn As Telerik.Windows.Controls.RadButton
    btn = CType(sender, Telerik.Windows.Controls.RadButton)

    Dim cell As Telerik.Windows.Controls.GridView.GridViewCell
    cell = btn.Parent()

    Dim row As Telerik.Windows.Controls.GridView.GridViewRow
    row = cell.Parent()

    If row IsNot Nothing Then   This is always nothing
      row.IsSelected = True

      Dim can As FoundVoters
      Dim sOffice As String = Nothing
      can = Search_RadDG.CurrentItem

      Dim wcf As New WCF_CommonDataContracts.DataCommon_WCF.WCF_Exception
      With can

        wcf = DistrictData.Candidate_New(StateCbx.SelectedItem,   Countylbx2.SelectedItem,      DistType_lbx.SelectedItem,
                                      ParseDistrictCode(Districts_lbx.SelectedItem), SubDistricts_cbx.SelectedItem,        .Voter_id,
                                            EDate_DP.SelectedDate,             4, sOffice)
      End With

      Candidate_List_Set()
    End If


2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 10 Jan 2011, 11:09 AM
Hi,

 The direct cell.Parent is not a GridViewRow - you should use our extension methods (ParentOfType<>() in this case) to get the parent row. You will need Telerik.Windows.Controls namespace to use these methods. 

If you want to work with the row data you can use DataContext of your button (or cell) directly. 

Kind regards,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Michael Luna
Top achievements
Rank 1
answered on 10 Jan 2011, 10:13 PM
Ok, I get it now but I alwasy get the first row from the search grid, not the row where I click on the Add button I added to the row.
Same Xaml as above
New VB....

 Dim btn As Telerik.Windows.Controls.RadButton
    btn = CType(sender, Telerik.Windows.Controls.RadButton)
    Dim row As GridViewRow
    row = btn.ParentOfType(Of GridViewRow)()

    If row IsNot Nothing Then
      row.IsSelected = True
      Dim can As FoundVoters
      can = Search_RadDG.CurrentItem

      Dim wcf As New WCF_CommonDataContracts.DataCommon_WCF.WCF_Exception
        wcf = DistrictData.Candidate_New(StateCbx.SelectedItem,   Countylbx2.SelectedItem,   DistType_lbx.SelectedItem,
                                      ParseDistrictCode(Districts_lbx.SelectedItem),
                                      SubDistricts_cbx.SelectedItem,   can.Voter_id,    EDate_DP.SelectedDate,   4, sOffice)
    End If

Tags
GridView
Asked by
Michael Luna
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Michael Luna
Top achievements
Rank 1
Share this question
or