2013-12-09 112 views
0

我有兩個datagrid gridproperty和gridpropertyselection。有一個包含數據的表格。我必須在dataGridviw中填充數據,該數據名爲gridpropertyselection accor to gridProperty datagrid中的選定行。根據另一個datagridview中的選定行填充datagridview

我想知道哪些事件將用於此目的。我介紹下面的代碼。但在Dim index中出現錯誤As Integer = gridProperty.CurrentRow.Index this line

Private Sub gridProperty_SelectionChanged(ByVal Sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowStateChangedEventArgs) Handles gridProperty.RowStateChanged 


    Dim dtPropertySelection As DataTable = m_ds.Tables(0) 

    Dim i As Integer 
    Dim count As Integer = gridPropertySelection.Rows.Count 
    ' If (gridProperty.CurrentRow.IsNewRow IsNot Nothing) Then 
    Dim index As Integer = gridProperty.CurrentRow.Index 
    Dim PropertyID As Integer = gridProperty.Rows(index).Cells("PropertyID").Value 
    While i < dtPropertySelection.Rows.Count 
     If PropertyID = dtPropertySelection.Rows(i).Item("PropertyID") Then 
      gridPropertySelection.Rows.Add() 
      gridPropertySelection.Rows(count).Cells("colSelectionDescription").Value() = dtPropertySelection.Rows(i).Item("SelectionDescription") 
      gridPropertySelection.Rows(count).Cells("colAssociatedText").Value() = dtPropertySelection.Rows(i).Item("AssociatedText") 
      count = count + 1 
     End If 
     i = i + 1 
    End While 

回答

0

您可以使用datagridview的CellClick事件。
另外,儘量使用
Dim index As Integer = gridProperty.CurrentCell.RowIndex()

+0

通過使用暗淡指數爲整數= gridProperty.CurrentCell.RowIndex()線也 – user2194838

+0

是有上的任何數據得到了錯誤「不設置到對象的實例對象引用」你的'gridProperty'?此外,請嘗試將事件更改爲CellClick,而不是更改選擇。 – Codemunkeee

+0

如果我正在使用cellclick事件,那麼選擇默認行,數據不會在表單加載時填充到另一個數據網格中 – user2194838