We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Locking Certain Rows in DataGrid

Hi! I find this site very helpful! Ok..here's my problem. When the user selects a row (in the data grid) that they want to edit, I want the other rows to be locked. Is this possible? Thanks in advance! :)

4 Replies

CB Clay Burch Syncfusion Team May 31, 2002 07:40 AM UTC

Can you explain your goal in more detail? You want the other rows locked until when? Normally, when a cell is in the edit mode, there is nothing happening in the other rows, so there is no reason for them to be locked? Is it that you want the user only to be able to change the focus to another cell in the same row? If so, what is the criteria for turning off this behavior, so the user can eventually select another row?


JO jolly June 1, 2002 12:40 AM UTC

I set the datagrid.readonly = true when the form loads. When the user selects a row that they want to edit, they have to click the edit button then the datagrid.readonly is set to true so they can edit the row. but while they are editing that row, they are still able to click on the other rows in the datagrid. I want to prevent them from doing that so the focus is only on the row that they want to edit. If they click on another row, i don't want the row to be highlighted b/c that is not the row they are editing. One more thing, when the user clicks on a cell, the whole row is highlighted and I want that. But if the user wants to edit a row, I want the focus to be on each cell that they want to edit..I want to turn off the highlighting the whole row. How do i do that? > Can you explain your goal in more detail? > > You want the other rows locked until when? Normally, when a cell is in the edit mode, there is nothing happening in the other rows, so there is no reason for them to be locked? > > Is it that you want the user only to be able to change the focus to another cell in the same row? If so, what is the criteria for turning off this behavior, so the user can eventually select another row?


CB Clay Burch Syncfusion Team June 1, 2002 07:55 AM UTC

I think you can do this by adding some memebers to track the editrow, editcolumn, whether you are editing and if the click to select a row is the first one after setting the edit switch. Then in a CurrentCellChanged event handler, depending on these switches, you can decide whether to allow the currentcell to move or not.
   private bool isFirstClick = false;
   private bool isEditing = false;
   private int editRow;
   private int editColumn;

   //toggles editing on/off
   private void button1_Click(object sender, System.EventArgs e)
   {
      if(isEditing)
         isEditing = false;
      else
      {
         isFirstClick = true;
         isEditing = true;
      }
   }

   private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
   {
      if(isEditing)
      {
         if(isFirstClick)
         {
            isFirstClick = false;
            editRow = this.dataGrid1.CurrentRowIndex;
         } 
         else if(this.dataGrid1.CurrentRowIndex != editRow)
         {
            this.dataGrid1.CurrentCell = new DataGridCell(editRow, editColumn);
         }

         editColumn = this.dataGrid1.CurrentCell.ColumnNumber;
      }
   }


JO jolly June 1, 2002 08:32 AM UTC

Thanks so much!!!! > I think you can do this by adding some memebers to track the editrow, editcolumn, whether you are editing and if the click to select a row is the first one after setting the edit switch. Then in a CurrentCellChanged event handler, depending on these switches, you can decide whether to allow the currentcell to move or not. >
>    private bool isFirstClick = false;
>    private bool isEditing = false;
>    private int editRow;
>    private int editColumn;
> 
>    //toggles editing on/off
>    private void button1_Click(object sender, System.EventArgs e)
>    {
>       if(isEditing)
>          isEditing = false;
>       else
>       {
>          isFirstClick = true;
>          isEditing = true;
>       }
>    }
> 
>    private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
>    {
>       if(isEditing)
>       {
>          if(isFirstClick)
>          {
>             isFirstClick = false;
>             editRow = this.dataGrid1.CurrentRowIndex;
>          } 
>          else if(this.dataGrid1.CurrentRowIndex != editRow)
>          {
>             this.dataGrid1.CurrentCell = new DataGridCell(editRow, editColumn);
>          }
> 
>          editColumn = this.dataGrid1.CurrentCell.ColumnNumber;
>       }
>    }
> >

Loader.
Live Chat Icon For mobile
Up arrow icon