Articles in this section

How to allow editing for a specific row in the readonly grid in WinForms GridGroupingControl?

Enable the edit mode


In WinForms GridGroupingControl, you can disable the edit mode by using the ReadOnly property, but you cannot enable the edit mode for particular rows.

 

Solution

You can disable the edit mode by handling the TableControlCurrentCellStartEditing event. By this event, you can enable the edit mode for selected rows.

In the provided sample, the selected row that has to be edited are added into a collection, and this collection is checked within the TableControlCurrentCellStartEditing event handle for editing.

 

//Trigger event
this.gridGroupingControl1.TableControlCurrentCellStartEditing += new GridTableControlCancelEventHandler(gridGroupingControl1_TableControlCurrentCellStartEditing);

void gridGroupingControl1_TableControlCurrentCellStartEditing(object sender, GridTableControlCancelEventArgs e)
{
   GridCurrentCell cc = e.TableControl.CurrentCell;
   // Editing is allowed only for the rows in the below collection
   e.Inner.Cancel = !(list.Count > 0 && list.Contains(cc.RowIndex));
}

private void button2_Click(object sender, EventArgs e)
{
   isallowedit = !isallowedit;
   if(isallowedit)
   {
      list.Clear();
      //Selected records added to the list
      foreach(SelectedRecord record in gridGroupingControl1.Table.SelectedRecords)
      {
         list.Add(record.Record.GetRowIndex());
      }
   }
   else
      list.Clear();
      isallowedit = false;
}

VB

'Trigger event
AddHandler gridGroupingControl1.TableControlCurrentCellStartEditing, AddressOf gridGroupingControl1_TableControlCurrentCellStartEditing

Private Sub gridGroupingControl1_TableControlCurrentCellStartEditing(ByVal sender As Object, ByVal e As GridTableControlCancelEventArgs)
   Dim cc As GridCurrentCell = e.TableControl.CurrentCell
   ' Editing is allowed only for the rows in the below collection
   e.Inner.Cancel = Not(list.Count > 0 AndAlso list.Contains(cc.RowIndex))
End Sub

Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)
   isallowedit = Not isallowedit
   If isallowedit Then
      list.Clear()
      'Selected records added to the list
      For Each record As SelectedRecord In gridGroupingControl1.Table.SelectedRecords
          list.Add(record.Record.GetRowIndex())
      Next record
   Else
      list.Clear()
   End If
   isallowedit = False
End Sub

Samples:

C#EnableEdit

VBEnableEdit 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied