how to set record pointer to current record in datagridview. i am used DataTable in C#

NazHim 206 Reputation points
2021-05-12T17:25:34.33+00:00

Hi All
how to set record pointer to current record in datagridview. i am used DataTable in C#
without database
i am added image

96059-screenshot-2021-05-12-220009.png
i am using code

int rowIndex = -1;  
foreach (DataGridViewRow row in proNamDetDataGridView.Rows)  
{  
     if (row.Cells["PND_Id"].Value.ToString().Equals(pndid))  
     {  
         rowIndex = row.Index;  
         proNamDetDataGridView.Rows[rowIndex].Selected = true;  
         break;  
     }  
 }  

get row value is wrong means, i am selected row is last one for modify. but got value from first row
because record pointer is stay in first row, i want to set record pointer at same selected row
can possible it?. if it. please provide some code snippets.

with best Regards
NazHim

Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2021-05-12T19:34:46.23+00:00

    Try executing one more line:

    proNamDetDataGridView.CurrentCell = proNamDetDataGridView.Rows[rowIndex].Cells[0];
    
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. NazHim 206 Reputation points
    2021-05-12T20:03:45.907+00:00

    hello Viorel-1
    thanks for your fast response
    i am tryed.

    proNamDetDataGridView.CurrentCell = proNamDetDataGridView.Rows[rowIndex].Cells[0];
    

    but getting error..!

    System.InvalidOperationException: 'Current cell cannot be set to an invisible cell.'

    with best regards
    NazHim


  2. NazHim 206 Reputation points
    2021-05-13T04:44:52.017+00:00

    Thanks Viorel-1
    it's worked fine

    int rowIndex = -1;
     foreach (DataGridViewRow row in proNamDetDataGridView.Rows)
     {
          if (row.Cells["PND_Id"].Value.ToString().Equals(pndid))
          {
              rowIndex = row.Index;
              proNamDetDataGridView.Rows[rowIndex].Selected = true;
              proNamDetDataGridView.CurrentCell = proNamDetDataGridView.Rows[rowIndex].Cells[1];
              break;
          }
      }
    

    thanks for your valubale advice

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.