unable to pre-select a value in my combobox column

Hello there, need your help,

i have a unbound combobox column in my DGV and i populated it using the following code

dgCboTask.DataSource = _ds.Tables["_dsTask"];
dgCboTask.ValueMember = "code";
dgCboTask.DisplayMember = "codedesc";

upon load form, i bind my DGV in using the following code

dataGridView1.DataSource = dsGridData;
dataGridView1.DataMember = "dsData";
dataGridView1.VirtualMode = true;

How could I display/pre-select a value in the combobox after form load.
I have hidden column in my DGV that contains the ID w/c must be the selectedValue to be displayed in my DGV combo box.


Thanks in advance guys!



Answer this question

unable to pre-select a value in my combobox column

  • digitalnetbizz

    Thanks Stefano!

    I got it already.


  • techie7999

    Hello,

    I think you should cycle the rows in your datagridview and for each row get the comboboxcell and set its value property.

    HTH

    Stefano



  • Kwen.de.Mike

    Thanks VVactor

    I think it will solve my problem



  • Wajahat Abbas

    Dear VVactor

    Just like your problem i am facing the same. I tried that but this is also not working.

    Actually it is showing me that index id of that item is selected at the time of line execution in code, while debugging. But it is not showing in the combobox that value selected or any other value selected.

    How you got it... Please reply me.



  • JasonMcC

    hi tats,

    here's what I did..

    foreach (DataRow _dr in dsGridData.Tables["dsData"].Rows)

    {

    DataGridViewComboBoxCell _cellCbo = (DataGridViewComboBoxCell)dataGridView1[dataGridView1.Columns["dgCboTask"].Index, _intRowIndex];

    _cellCbo.Value = _dr["comboBoxValue"].ToString();


  • unable to pre-select a value in my combobox column