Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>// Add a new Column (ComboBox) </p> <pre><code>DataGridViewComboBoxColumn colForeign = new DataGridViewComboBoxColumn(); colForeign = MyDB.CreateComboBoxColumn("SELECT subjno,subject FROM subject", "ComboForeign", "subject", "subjno"); colForeign.HeaderText = "Subject"; colForeign.Width = 120; colForeign.DisplayStyle = 0; this.dataGridView2.Columns.Insert(3, colForeign) Use DataPropertyName to get the selected key column as in :- this.dataGridView2.Columns[3].DataPropertyName = "subjno"; </code></pre> <p>It appears that this would be much easier in VisualStudio - maybe?? And here is the routine to Create the Combobox Column - very messy compared with Delphi :-</p> <pre><code>public DataGridViewComboBoxColumn CreateComboBoxColumn(string strSQLSelect, string strColName, string strDisplay, string strValue) { // Returns the DataGridViewComboBoxColumn to be inserted DataGridViewComboBoxColumn colComboColumn = new DataGridViewComboBoxColumn(); DataTable dtbElements = new DataTable(); MySqlDataAdapter dbaElements = new MySqlDataAdapter(strSQLSelect, conn); // Set some parameters for the ComboBoxColumn colComboColumn.Name = strColName; colComboColumn.DisplayMember = strDisplay; colComboColumn.ValueMember = strValue; // Add the Elements dbaElements.Fill(dtbElements); colComboColumn.DataSource = dtbElements; // Return the column return colComboColumn; } </code></pre> <p>If the userAddedRow flag is set to true, unset the flag; userAddedRow = false; and set id to 0, valid because autoincremented id's from server starting from 1 :-</p> <pre><code>dataGridView1["bookno", e.RowIndex].Value = 0; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload