|
-
Apr 7th, 2006, 09:54 PM
#1
Thread Starter
Lively Member
[2.0] DataGridView -- Select Items
Ok, so I have six Colums that are all loaded into the DataGridView, each coloumn as info in it. How could I get the text of each selected item in the 2 column?
Somthing like.
Code:
foreach(object item in this.DGV.SelectedItemsINCol2)
{
MessageBox.Show(item.ToString());
}
Thanks
-
Apr 8th, 2006, 06:05 AM
#2
Re: [2.0] DataGridView -- Select Items
The DataGridView has a SelectedRows property that is a DataGridViewSelectedRowCollection.
The DataGridViewSelectedRowCollection has an Item property that is a DataGridViewRow.
The DataGridViewRow has a Cells property that is a DataGridViewCellCollection.
The DataGridViewCellCollection has an Item property that is a DataGridViewCell.
The DataGridViewCell has a Value property that is an Object and is the value displayed in the cell.
-
Apr 8th, 2006, 10:06 AM
#3
Thread Starter
Lively Member
Re: [2.0] DataGridView -- Select Items
Do you think you could give me a small example? I couldnt firgure it out.
-
Apr 11th, 2006, 08:11 AM
#4
Hyperactive Member
Re: [2.0] DataGridView -- Select Items
Code:
foreach (DataGridViewRow dgvr in ConcernTableView.SelectedRows)
{
//
// You can do it by cell index number
//
MessageBox.Show(dgvr.Cells[2].Value.ToString());
//
// Or you can do it by name which is much better!!!!
//
MessageBox.Show(dgvr.Cells["id"].Value.ToString());
//
// Or if you are binding something, you can get the class
//
MessageBox.Show(((Concern)dgvr.DataBoundItem).Id.ToString());
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|