【问题标题】:how to get the Hidden Columns Control Value in PreparingCellForEdit Silverlight Datagrid如何在 PreparingCellForEdit Silverlight Datagrid 中获取隐藏列控件值
【发布时间】:2013-08-04 05:48:49
【问题描述】:

如何在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 列,并且我正在识别标签控件对象但内容变为空..

【问题讨论】:

    标签: silverlight datagrid silverlight-4.0


    【解决方案1】:

    一切正常

    1) 在 Loading Row 事件中我们不应该隐藏 Column,如果隐藏列则无法从列中获取值,让数据在 LoadingRow 事件中首先加载。

    2) 隐藏Selection changed事件代码中的列如下:

     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
    

    一旦加载 Row,此事件将在 LoadingRow Datagrid 事件或 PreparingCellForEdit 事件之后触发,我们可以隐藏列并可以在任何你想要的地方获取值。如果你隐藏在 LoadingRow 事件中而不加载数据,你将无法获得值Datagrid 模板或数据列中的那个控件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-24
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 2015-08-18
      • 2011-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多