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

selecting rows from DataGridView

Expert 100+
P: 1,025
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 😉
4 Weeks Ago #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+
1 Reply


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

Post your reply

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