Note that there are some explanatory texts on larger screens.

plurals
  1. POError after setting different datasources for datagridview combobox cells
    primarykey
    data
    text
    <p>I am trying to display in <code>DataGridView</code> control names and fields of database tables. In every row name of a table is displayed in the first cell, and second column allows to choose any of the fields of that table.</p> <p>To do that, I am handling 'DataGridView.CellBeginEdit' event and fill DataSource for cell with names of the fields. When I am trying to edit those cells, provided list is displayed correctly and can b chose just fine.</p> <p>However when I try to do the same in another row, I start getting <code>DataError</code> events about the cell I have edited.</p> <p>Event arguments for DataRow have 'Formatting|Display' in <code>Context</code> field, and have the message "Value not allowed in DataGridViewComboBoxCell" (or close to it). In debug, the cell event references has correct <code>Value</code> field, but its <code>DataSource</code> is null and its <code>FormattedValue</code> is empty string. And previously displayed text changes to blank.</p> <p>How should this be resolved correctly? Should I derive my own custom datagridview cell that displays text but has a combobox editor? If so, how?</p> <p>Edit: here is code I am currently using:</p> <pre><code>public class FieldDataNeededEventArgs: EventArgs { public List&lt;string&gt; FieldNames { get; private set; } public string TableName { get; private set; } public ReferenceFieldDataNeededEventArgs(stringdata) : base() { FieldNames = new List&lt;string&gt;(); TableName= data; } } ... public event EventHandler&lt;FieldDataNeededEventArgs&gt; FieldDataNeeded = new EventHandler&lt;FieldDataNeededEventArgs&gt;((sender, args) =&gt; { }); ... //handler for CellBeginEdit //dgvMatch - dataGridView, DocsReferenceToTableMatch is class that datagridview is bound to private void dgvMatch_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { if (e.ColumnIndex == dgvMatch.Columns["TableKey"].Index) { DocsReferenceToTableMatch data = dgvMatch.Rows[e.RowIndex].DataBoundItem as DocsReferenceToTableMatch; FieldDataNeededEventArgs ea = new FieldDataNeededEventArgs(data.TableName); FieldDataNeeded(this, ea); var cell = (dgvMatch.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewComboBoxCell); cell.DataSource = ea.FieldNames; } } //example handler for the FieldDataNeeded event static void ld_ReferenceFieldDataNeeded(object sender, ReferenceFieldDataNeededEventArgs e) { for (int i = 0; i &lt; 4; i++) { e.FieldNames.Add(String.Format("{0}_fld{1}", e.ReferenceName, i)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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