Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 Framework compact
I am working with a windows app and have a form that contains a datagridview that has bound and unbound controls. My dropdowns have 2 parts - item and the value. (A = some value1; B = some value2, and so on). Item = A;B... Value = some value1; some value2.....
 
The user sees this in the dropdown - "some value1"
 
The value going into the subtable is: "A = somevalue1"
 
I need to enter Item "A" into the database table, but am having difficulty grabbing it.
 
The text fields load to the database fine. How do I get the correct value from the datagridview dropdowns?
 
I currently have:
               for (int i = 0; i < dataGridView1.Rows.Count; i++)
               {
                   for (int j = 0; j < dataGridView1.Columns.Count; j++)
                   {
                       if ((dataGridView1.Rows[i].Cells[j].Value != null) &&
                            (dataGridView1.Rows[i].Cells[j].Value.ToString().Trim() != ""))
                       {
                           myRow[dataGridView1.Columns[j].Name.Trim()] = dataGridView1.Rows[i].Cells[j].Value.ToString().Trim();
                           l_blnWrite = true;
                       }
                       else
                       {
                           l_blnWrite = false;
                           break;
                       }
                   }
                   if (!l_blnSavedRecord)
                    {
                        if(l_blnWrite)
                            ds.Tables[l_strTable].Rows.Add(myRow);
                    }
                }
Posted 27-Mar-13 5:26am
ptslv389
Edited 27-Mar-13 6:26am
v4
Comments
YAIR-I at 27-Mar-13 12:56pm
   
The dropdowns are columns in the datagrid view?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Yes, there are a combination of field types that are columns, Text and combo boxes.
  Permalink  

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

  Print Answers RSS
0 Maciej Los 310
1 OriginalGriff 285
2 Afzaal Ahmad Zeeshan 200
3 Sergey Alexandrovich Kryukov 195
4 BillWoodruff 180
0 OriginalGriff 6,499
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,193
3 Manas Bhardwaj 4,657
4 Maciej Los 4,120


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100