By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,752 Members | 2,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,752 IT Pros & Developers. It's quick & easy.

selecting rows from DataGridView

Expert 100+
P: 1,039
I am filling a datagridview with picture data (names, sizes), and trying to select certain rows.

Expand|Select|Wrap|Line Numbers
  1. int[] s = new int[100];
  2.  
  3. foreach (var fileName in Directory.GetFiles(folder))
  4. {
  5.    FileStream stream = File.OpenRead(fileName);
  6.    Image i = Image.FromStream(stream, false, false);
  7.    values[3] = i.Width;
  8.    values[4] = i.Height;
  9.    stream.Close();
  10.    int r = dataGridView1.Rows.Add(values);
  11.    s[r] = (!(bool)values[5] && (int)values[3]>1000 ? r : 0);
  12. }
  13. var selection = from t in s where t > 0 select s[t];
  14. foreach (var item in selection)
  15. {
  16.    dataGridView1.CurrentCell = dataGridView1.Rows[item].Cells[0];
  17.    dataGridView1.Rows[item].Selected = true;
  18. }
  19.  
The selection is done bases on the code on line#11 (which is OK for me!)

My problem is the fact that only 1 row is selected, but debugging the foreach on line #13 shows I should have at least two lines in my selection (today).

A short explanation on why this code is wrong would be appreciated 😉
Apr 20 '19 #1

✓ answered by Luuk

Thanks for thinking with me,
I pushed CTRL+A, DEL, and rewrote this.
Now it's doing what I think it should be doing.

Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,039
Thanks for thinking with me,
I pushed CTRL+A, DEL, and rewrote this.
Now it's doing what I think it should be doing.
Apr 22 '19 #2

100+
P: 111
Expand|Select|Wrap|Line Numbers
  1.    dataGridView1.CurrentCell = dataGridView1.Rows[item].Cells[0];
  2.  
The previous selection is deselected for this line.
Do you need this line?
Jan 22 '20 #3

Post your reply

Sign in to post your reply or Sign up for a free account.