1

我陷入了需要禁用每行中的几列的情况,除了新添加的行。

也就是说,我在网格中有 10 列,前 3 列是数据绑定的,并且来自数据库作为禁用或只读。其余的都是可编辑的。

如果我添加一个新行,则必须启用新行的所有列,直到它被保存。

我的现有行或新行没有任何 DataKey 或主键。我必须检查一些布尔值,例如IsNewRow.

在我目前的情况下,我正在使用这个代码块:

Private Sub dgTimeSheet_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles dgTimeSheet.InitializeRow

    ''if either column key is Project, Class or Milestone

    '' Activation.NoEdit = Disable and Activation.AllowEdit = Enable

    Dim index As Integer = e.Row.Index

     If e.Row.IsAddRow Then

        dgTimeSheet.Rows(index).Cells(PROJECT).Activation = Activation.AllowEdit

        dgTimeSheet.Rows(index).Cells(SERVICE_ISSUE_CLASS).Activation = Activation.AllowEdit

        dgTimeSheet.Rows(index).Cells(MILESTONE).Activation = Activation.AllowEdit

     Else

        dgTimeSheet.Rows(index).Cells(PROJECT).Activation = Activation.NoEdit

        dgTimeSheet.Rows(index).Cells(SERVICE_ISSUE_CLASS).Activation = Activation.NoEdit

        dgTimeSheet.Rows(index).Cells(MILESTONE).Activation = Activation.NoEdit


    End If

    CheckRows()

End Sub

问题是,如果我单击禁用/只读行,那么新添加的行也会被禁用,这是我不想要的。

4

2 回答 2

0

我正在与 C# 中的类似问题作斗争,所以这是在黑暗中钓鱼......在你的情况下,是否有可能添加 IgnoreRowColActivation = true 语句来防止行恢复?

于 2010-10-29T21:33:16.190 回答
0

此示例为客户使用的界面创建只读列

具有三列的行的示例。将两列设置为只读,第三列设置为用户可编辑。

设计器中定义的三列:System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn2; System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;

直接设置第 1 列和第 2 列

this.dataGridViewTextBoxColumn1.ReadOnly = true
this.dataGridViewTextBoxColumn2.ReadOnly = true

您仍然可以更新源代码中的所有列。客户将只能编辑第三列。

于 2015-02-12T19:40:59.397 回答