Link to home
Start Free TrialLog in
Avatar of Jayesh Acharya
Jayesh AcharyaFlag for United States of America

asked on

delete a row in a datagrid

I am trying to delete a specific row in my datagrid, I am able to highlight a row and I can delete a row but the row I delete is always the bottom row of the grid.

I dont know how to pass the information of the row / rows I highlighted to delete

heres is the code i use to delete
        private void deleteRow_Click(object sender, EventArgs ee)
        {
            StockCheckDataTable.Rows[dataGridView1.SelectedRows[0].Index].Delete(); }

dont know how to pass the correct id for the row i highlighted ...
Avatar of Jayesh Acharya
Jayesh Acharya
Flag of United States of America image

ASKER

ok found the answer

                int yCoord = dataGridView1.CurrentCellAddress.Y;
                StockCheckDataTable.Rows[yCoord].Delete();
SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If i highlight multiple rows, is their a way to delete all the rows i highlighted, currently i just delete the last row of all the rows i highlight
Then you need to loop through the "SelectedRows" and delete them one by one.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fantastic help easy to understand solutions thnask a lot