What's Here?
- Members: 107,646
- Replies: 409,498
- Topics: 62,191
- Snippets: 2,253
- Tutorials: 601
- Total Online: 913
- Members: 45
- Guests: 868
Who's Online?
|
Welcome to Dream.In.Code |
|
|
Getting C# Help is Easy!
Join 107,646 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 913 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
|
Returns a list of all DataRows selected in DataGridView.
|
Submitted By: baavgai
|
|
Rating:
 
|
|
Views: 5,644 |
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
|
|
|
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|