Click here to Skip to main content
11,704,107 members (58,011 online)
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 4:26am
ptslv389
Edited 27-Mar-13 5: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 Sergey Alexandrovich Kryukov 745
1 OriginalGriff 520
2 Maciej Los 475
3 Andy Lanng 284
4 CPallini 275
0 OriginalGriff 8,784
1 Sergey Alexandrovich Kryukov 7,843
2 CPallini 5,107
3 Maciej Los 4,726
4 Mika Wendelius 3,606


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2015
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