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.
Unfortunately, activation email could not send to your email. Please try again.

Locking Certain Rows in DataGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

303 May 30,2002 11:29 PM Jun 1,2002 04:32 AM Windows Forms 4
loading
Tags: FAQ
jolly
Asked On May 30, 2002 11:29 PM

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! :)

Clay Burch [Syncfusion]
Replied On May 31, 2002 03:40 AM

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?

jolly
Replied On May 31, 2002 08:40 PM

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?

Clay Burch [Syncfusion]
Replied On June 1, 2002 03:55 AM

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;
      }
   }

jolly
Replied On June 1, 2002 04:32 AM

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;
>       }
>    }
> >

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;