Question

I am stuck in a situation where I need to disable a few columns in each row, except for the newly added row.

That is, I have 10 columns in the grid and the first 3 columns are databound and come from the database as disabled or read-only. The rest are editable.

If I add a new row, then all the columns of the new row must be enabled until it is saved.

I don't have any DataKey or primary key for my existing row or the new row. I have to check for some boolean value like IsNewRow.

In my current scenario I am using this code block:

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

The problem is that if I click on disabled/read-only rows, then newly added rows also get disabled, which I don't want.

Was it helpful?

Solution

I am fighting with a similar problem in C#, so this is fishing in the dark... Is it possible, in your case, to add an IgnoreRowColActivation = true statement to keep the rows from reverting?

OTHER TIPS

This examples create read only columns for the interface a customer uses

Example for a row with three columns. Set two columns as readonly and the third as editable to the user.

the three columns defined in the designer: System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn1; System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn2; System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;

set column 1 & 2 directly

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

You can still update all columns in the source code. The customer will only be able to edit the third column.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top