Click here to Skip to main content
15,885,662 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I Have a datagridview like this

id name age
-----------
1 AAA 22
2 BBB 23
3 CCC 33
4 DDD 44

I want to add id values to an int array on click of id cell..

thx in advance...
Posted

1 solution

I think it will be easy to add the IDs to a list. However, if you want an array ToArray() method of List<T>class can be used.

C#
List<int> IdList = new List<int>();

private void dataGridView1_CellClick(object sender,
    DataGridViewCellEventArgs e)
{
    IdList.Add(Convert.ToInt32(dataGridView1.Rows[e.RowIndex]
        .Cells[e.ColumnIndex].Value));
}
 
Share this answer
 
v3
Comments
Ravi Sargam 15-Mar-12 5:05am    
Thank you... it's working...
Thx again
ProEnggSoft 15-Mar-12 5:24am    
Thank you
Ravi Sargam 15-Mar-12 5:32am    
Hey Can you find solution for this question "add group's total values in Crystal Reports and show in same report
"
ProEnggSoft 15-Mar-12 8:17am    
Sorry, I am not using Crystal Reports. Thank you
ProEnggSoft 15-Mar-12 8:16am    

To the member who has downvoted:

Can you please give the reason for down voting, to know what is the deficiency.

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