2017-01-01 121 views
0

我有一個gridcontrol(GridControl1) 內THID gridcontrol選擇行項目,在兩個網格視圖(GridView1 & GridView2) 我想選擇行項目的價值在GridView2並把它放在一個文本框。 上GridView1我可以得到使用此代碼:獲得來自gridview2

txtEmpId.Text = GridView1.GetFocusedRowCellDisplayText(colEmp_Id) 

但如果我上GridView2選擇任意行,沒有什麼我會得到。

有沒有辦法做到這一點。

回答

1

如果您已使用主詳細請查看help article describing in detail

在你GridControl你必須處理Grid_MasterRowExpanded,然後把手添加programmaticuly到gridView.SelectionChanged,該代碼將幫助您

Private Sub Grid_MasterRowExpanded(ByVal sender As System.Object, ByVal e As DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs) Handles Grid.MasterRowExpanded 
     Dim view As GridView = sender 
     Dim detail As GridView = view.GetDetailView(e.RowHandle, e.RelationIndex) 
     detail.OptionsSelection.MultiSelect = True 

     If e.RowHandle = 0 Or e.RowHandle = 1 Then 
      AddHandler detail.SelectionChanged, AddressOf detail_SelectionChanged 
     End If 

    End Sub 

    Private Sub detail_SelectionChanged(ByVal sender As System.Object, ByVal e As DevExpress.Data.SelectionChangedEventArgs) 

     viewSelected = sender 

     Dim ro As DataRowView = viewSelected.GetFocusedRow 
     txtEmpId.Text = ro.Item("colEmp_Id") 

    End Sub 
+0

同樣的問題,文本框仍然是空的。我正在使用主細節。 – Jassimi

+0

好的使用Dim ro As DataRowView = viewSelected.GetFocusedRow; txtEmpId.Text = ro.Item(「colEmp_Id」) –

+0

仍然一樣,沒有解決。 – Jassimi