2013-08-04 65 views
0

如何讓隱藏的列控制值PreparingCellForEdit的Silverlight的Datagrid如何讓隱藏的列控制值PreparingCellForEdit的Silverlight的Datagrid

代碼如下:

Private Sub TaskDataGrid_LoadingRow(ByVal sender As System.Object, ByVal e As 
System.Windows.Controls.DataGridRowEventArgs) 

    Dim row As DataGridRow = e.Row 
    Dim cellContent As FrameworkElement = TaskDataGrid.Columns(8).GetCellContent(e.Row) 

    Dim cboLabValidated As ComboBox = CType(cellContent.FindName("cboLabValidated"), ComboBox) 
    Dim ViewModel As New NonFirmWareNewRequestViewModel() 
    If cboLabValidated IsNot Nothing Then 
     cboLabValidated.ItemsSource = ViewModel.YesNoValues 
    End If 
    TaskDataGrid.Columns(1).Visibility = Visibility.Collapsed 
End Sub 

在上面的代碼我藏了在LoadingRow事件,需要列1至獲得PreparingCellForEdit該列的值

代碼PreparingCellForEdit如下:

Dim fe As FrameworkElement = TaskDataGrid.Columns(5).GetCellContent(e.Row) 
        Dim fe1 As FrameworkElement = TaskDataGrid.Columns(1).GetCellContent(e.Row) 

        Dim gridCmbo As Grid = DirectCast(fe, Grid) 

        Dim gridCmbo1 As Grid = DirectCast(fe1, Grid) 

        Dim lbltaskId As Label = CType(gridCmbo1.FindName("lbltaskId"), Label) 

        Dim cboCompVerSel As ComboBox = CType(gridCmbo.FindName("cboCompVerSel"), ComboBox) 

        Dim lblCompVer As Label = CType(gridCmbo.FindName("lblCompVer"), Label) 

我使用標籤控件顯示列1,我識別標籤控件對象,但內容變成空..

回答

0

這是工作的罰款

1),而在加載行事件我們不應該隱藏列,如果你隱藏了列,你不能從列中獲得值,那麼讓LoadRow事件首先載入數據。

2)隱藏在選擇改變事件代碼列如下:

Private Sub TaskDataGrid_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles TaskDataGrid.SelectionChanged 
     TaskDataGrid.Columns(1).Visibility = Visibility.Collapsed 
    End Sub 

一旦該行被加載,我們可以隱藏列,可以得到本次活動將LoadingRow Datagrid的事件或PreparingCellForEdit事件後觸發值。如果您在LoadRow事件中隱藏而不加載數據,則無法在Datagrid模板或數據列中獲取該控件的值。