Click here to Skip to main content
15,798,037 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
need help trying to compare datagridview data with list box in c# the datagridview data is entered manuly by typing it in what im trying to do is search a listbox with datagridview data
this is what i have so far

Thank you in advance.

What I have tried:

C#
foreach (DataGridViewRow row in dataGridView2.Rows)
            {
                //datafridview cell[0] is textbox
                //datagridview cell[1] is checkbox

                //if datagridview cell[0] text is in listbox3 items
                if (row.Cells[0].Value == listBox3.Items)

                {
                //if item is in listbox3 then checkbox checked
                 row.Cells[1].Value = true;


                }
                else
                {
               //if item is not in listbox3 then checkbox unchecked
                 row.Cells[1].Value = false;

                }
Posted
Updated 3-Mar-21 6:58am

1 solution

You cannot compare an individual value with a list of items. Also the value may not be a string so it will never match. You need to get the DataGridView item as a string, and then use the ListBox.FindString Method (System.Windows.Forms) | Microsoft Docs[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900