Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was trying to retirve the selected row values of my datagrid.. But gettting only one row even if i select more than one..
please find my code below
C#
foreach (DataGridViewRow dataGridViewRow in myDataGridView.SelectedRows)
{                addNewResourceDictionary.Add(dataGridViewRow.Cells[0].Value.ToString(), dataGridViewRow.Cells[1].Value.ToString()); ;
}




please advise
Posted

1 solution

C#
foreach (DataGridViewRow dGRow in myDataGridView.SelectedRows)
            {

addNewResourceDictionary.Add(dataGridViewRow.Rows[dGRow].Cells[0].Value.ToString(), dataGridViewRow.Rows[dGRow].Cells[1].Value.ToString()); 

            }
 
Share this answer
 
Comments
arun_pk 31-May-11 3:30am    
Thanks for the reply but i am getting some compilation error becoz
dataGridViewRow.Rows[dGRow]// Rows are taking integer index

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