Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
Updated 27-Mar-13 5:26am
v4
Comments
YAIR-I 27-Mar-13 12:56pm    
The dropdowns are columns in the datagrid view?

1 solution

Yes, there are a combination of field types that are columns, Text and combo boxes.
 
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