What's Here?
- Members: 148,616
- Replies: 504,664
- Topics: 79,460
- Snippets: 2,659
- Tutorials: 705
- Total Online: 1,287
- Members: 84
- Guests: 1,203
|
Returns a list of all DataRows selected in DataGridView.
|
Submitted By: baavgai
|
|
Rating:

|
|
Views: 8,454 |
Language: C#
|
|
Last Modified: December 31, 1969 |
Snippet
public List<DataRow> GetSelected(DataGridView dgv) {
List<DataRow> list = new List<DataRow> ();
if (dgv.SelectedRows == null || dgv.SelectedRows.Count == 0) {
return list;
}
foreach (DataGridViewRow dgvRow in dgv.SelectedRows) {
DataRow row = null;
try {
DataRowView drv = (DataRowView)dgvRow.DataBoundItem;
row = drv.Row;
} catch (Exception ex) {
Debug.WriteLine("Error: " + ex.Message);
}
if (row == null) { continue; }
list.Add(row);
}
return list;
// I prefer the List<DataRow> generic, if you prefer arrays then
// changed the return type to DataRow[], comment out the prior
// reuturn and use this one
// return list.ToArray();
}
Copy & Paste
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|