473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

selecting rows from DataGridView

1,047 Expert 1GB
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.

2 2275
Luuk
1,047 Expert 1GB
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
SioSio
272 256MB
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

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

Similar topics

0
by: Jaime | last post by:
Hi, I have a dataTable and I select some rows with the mouse. I am able to delete the rows selected with the mouse, but I can't figure out how to determine which rows are selected. I need this...
0
by: Steven W | last post by:
I'm trying to setup a datagrid in a custom control where I can select the row with the Select column hidden and have it call the "SelectIndexChanged" event. In the "SelectIndexChanged" I just want...
3
by: Zvonko | last post by:
hi! I have two tables with same structure. I need to run a select query that will return only the rows from one table that are not in the other. In MySQL it would be select * from table1...
0
by: | last post by:
I am testing the following piece of code: Is it possible to list the row number containing the checked box? After checking the desired box, I would want a message box to popup listing the row...
2
by: ewingate | last post by:
I have a form with two text boxes, a button, and a datagrid control which is bound to my SQL DB. There are two columns on the datagrid, one for each of the textboxes on the form. I have already...
1
by: nolanson | last post by:
I'm raw with MS Access and have been stumped for hours and hours on this. I have a table that has ticket rows (like an invoice - identified by a unique service date and call number) and remit rows...
8
by: jcstanley | last post by:
Hi I currently have a table that shows the details of every member in the database. What i am trying to achive is a way of providing the user with a method of selecting individual users...
3
by: magikminox | last post by:
Hi Folks I have a table in this format TradeID ActionID 58096 3664 58096 3665 58097 3685 58097 3687 …..
7
by: raj | last post by:
Hi, can any one help me in solving this issue i have a table test with 3 columns (city,state,country) of datatype varchar and notnull a b c x y z d ...
2
by: AgentOfFortune | last post by:
I have a DataGridView with a DataSource and I cannot select any rows or scroll through the grid. I click on the grid and nothing and when I try the up/down arrow keys the combo box scolls and not...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.