MarcDV
2021-02-05T14:59:32Z
Hello,

I run the following code to put a drop-down list in each cell (it works !)


MySqlDataReader RdrSecteur = Cnx.ExecuteSql("SELECT Sct_Id, Sct_Libelle FROM Secteur ORDER BY Sct_Libelle");
iGDropDownList dplSecteur = new iGDropDownList();
dplSecteur.FillWithData(RdrSecteur, "Sct_Id", "Sct_Libelle");

string Sql = "SELECT Id, Secteur, Service, Traducteur, Middleware FROM v_tbl_Gestionnaire";

DataSet myDataSet = new DataSet();
myDataSet = SelectRows(myDataSet, Sql);

iGridGestionnaire.FillWithData(myDataSet.Tables[0]);

iGridGestionnaire.Cols[1].CellStyle.DropDownControl = dplSecteur;

I take the value --> OK

string text = iGridGestionnaire.Cells[2, "Secteur"].Text.ToString(); --> Sct_Libelle


How can I retrieve the id from my controlbox in a grid cell ?

string value_id = iGridGestionnaire.Cells[2, "Secteur"]... ; --> Sct_Id ?????

Thank you for your help ;-)
Igor/10Tec
2021-02-05T16:34:28Z
If we understand your question properly, the id value should be placed into the cell value:

iGridGestionnaire.Cells[2, "Secteur"].Value

Have you tried to retrieve this expression?

FYI: Please, ask technical questions in this 'Questions and Issues' forum section.
MarcDV
2021-02-06T17:41:24Z
Sorry for not being in the right section ;-)

I tried your proposal but let it be :

string b = iGridGestionnaire.Cells[2, "Secteur"].Tetxt.ToString();
or
string c = iGridGestionnaire.Cells[2, "Secteur"].Value.ToString();

This gives the same answer.

In fact I associated a combobox to a column. This one is composed of an ID and a value.
This displays the value when you select a cell of this column. Perfect.
On the other hand I thought that it would store (somewhere in the cell) the ID.
But I can't find it.

Maybe with this
string b = iGridGestionnaire.Cells [2, "Sector"].DropDownControl
but how?
Igor/10Tec
2021-02-08T06:43:55Z
Do you attach the drop-down list to the column's cell style AFTER you have populated the grid? If so, then iGrid does not know that it must link cell values to drop-down list items.

In any case, it would be nice to see an example demonstrating your problem. Can you send us a simple solution we can launch on our side? You can replace replace real data providers with local DataTables or something like that to demonstrate the issue.

Before packing the solution to zip, please, remove the bin, obj and the hidden .vs subfolders with executable contents.
MarcDV
2021-02-10T15:00:26Z
Hello and sorry for the delay ;-)

I'm sending you an example. The questions are in the source code.

Thank you for your answers
  TestGridCombo.zip (16kb) downloaded 3 time(s).
Igor/10Tec
2021-02-10T15:32:58Z
Yes, I was right. You attach the drop-down list AFTER you added data to the grid. Look at this part of your code:

iGrid1.FillWithData(myDataSet.Tables[0], true);
iGrid1.Cols[1].CellStyle.DropDownControl = dplCombo;

To solve your problem, you can create the required set of columns before calling FillWithData and link dplCombo before you call FillWithData. Or, if you want to save some time and make your code universal, use the following trick instead.

Call iGrid's FillWithData right after you created the main table (i.e. when it does not have data rows yet):

DataTable dtA = new DataTable(); 
dtA.Clear();
dtA.Columns.Add("Id");
dtA.Columns.Add("ValueCombo");
dtA.Columns.Add("Item");

iGrid1.FillWithData(dtA);

Then use the following code to attach the drop-down list and populate your grid:

iGrid1.Cols[1].CellStyle.DropDownControl = dplCombo;
iGrid1.FillWithData(myDataSet.Tables[0], true);

Pay attention to the second Boolean parameter of the overloaded FillWithData version I used. It forces iGrid to use the existing column set with the drop-down list attached to the 2nd column.

This solution is an answer to both questions. You will see what you expect in the combo cells and the cell value and cell text will return the ID and Text respectively.
MarcDV
2021-02-11T07:36:13Z
Impeccable!

I would not have found this trick to first initialize the grid with the table and then add the drop-down list .
And finally to only complete with the data from the table.

Thank you!