Click here to Skip to main content
15,916,846 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have create a datagridview, and I don't want the first column to be editable with textboxes. So, I need to know the location of the current cell column and row.

And do I get the possition?
Posted

If the entire first column should not be editable, you can just set the column's ReadOnly property to True when you are setting up the grid. Probably in the LoadEvent:

dgvGrid.Columns("columnName").ReadOnly = True
 
Share this answer
 
Hi,

Use the inbuilt event of the datagridview. Add and set a contextmenustrip for the datagridview from property explorer. Add menuitems you want for the gridrow when user rightclicks it.

Finally write your code in the following event:

C#
private void dgvProducts_RowContextMenuStripNeeded(object sender, DataGridViewRowContextMenuStripNeededEventArgs e)
        {
            int indexOfClickedRow = e.RowIndex;
            dgvProducts.Rows[indexOfClickedRow].Selected = true;
           
            if(indexOfClickedRow==1) //or 0
            {
                  //Do Something
            }
            else
            {
                  //Do Something
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900