简体   繁体   中英

Get ComboBox ValueMember from DataGridview

I'm trying to get the ValueMember of a ComboBox that is in a Datagridview cell from a button click event:

    private void button2_Click(object sender, EventArgs e)
    {
        try
        {
            DataSet ds = new DataSet();

            OleDbDataAdapter t3DataAdapter = new OleDbDataAdapter(new OleDbCommand("SELECT * FROM Adok;", conn));
            OleDbCommandBuilder t3Command = new OleDbCommandBuilder(t3DataAdapter);
            t3DataAdapter.FillSchema(ds, SchemaType.Source, "Adok");

            for (int i = 0; i < dataGridView3.Rows.Count; i++)
            {
                DataRow row4 = ds.Tables["Adok"].NewRow();
                row4["HoltID"] = ((ComboBox)dataGridView3["HoltID", i]).ValueMember ;// I would like to get something like this

                ds.Tables["Adok"].Rows.Add(row4);
            }
        }
   }

The problem was that I created a ComboBox in CellBeginEdit event, but in the CellEndEdit event I hid it and the value was added to the cell value. (So the cell type was a DataGridViewTextBoxCell at the end, not a DataGridViewComboBoxCell)

So I used the the Tag property of the cell in CellEndEdit to save also the ID.

Now, everything works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM