Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to select an item from a filling of a DataGridViewComboBox
    primarykey
    data
    text
    <p>Project: Winforms, .NET framework: 3.5 (Visual Studio 2008)</p> <p>My problem is:</p> <p>I have a <code>DataGridView</code> with several columns, some of the type and another type <code>DataGridViewTextBoxColumn</code>, <code>DataGridViewComboBoxColumn</code>, <code>DataGridViewComboBoxColumn</code> column is filled by an entity supplied by the Entity Framework.</p> <pre><code>// Example ((System.ComponentModel.ISupportInitialize)(this.EntityBindingSource)).BeginInit(); this.EntityBindingSource.DataSource = this.dtContext.ExampleEntity; this.ComboColumn.DataSource = this.EntityBindingSource; this.ComboColumn.DataPropertyName = "ExampleId"; this.ComboColumn.DisplayMember = "Example"; this.ComboColumn.ValueMember = "ExampleId"; </code></pre> <p>When you run and load the form, fine</p> <p>But the problem comes when at runtime I want to select an item from the collection of <code>DataGridViewComboBoxColumn</code></p> <p>That in the event <code>CellEndEdit</code></p> <pre><code>private void dgvDetalle_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewCell cell = dgvDetalle.CurrentCell; DataGridViewComboBoxCell comboCell = (DataGridViewComboBoxCell)this.dgvDetalle.CurrentRow.Cells["ComboColumn"]; // Attempt 1 comboCell.Value = (ExampleEntity)comboTarifaImpuesto.Items[0]; // Attempt 2 comboCell.Value = ObjetoEntity; // Attempt 3 comboCell.Value = "ValueExample" // Attempt 4 comboCell.Value = ObjetoEntity.ToString(); } </code></pre> <ul> <li>Try selecting one item from combobox</li> <li>Try selecting an object of the entity</li> <li>Try selecting by means of a chain or Display Member Value</li> </ul> <p>and I can not select the desired items, I get the exception:</p> <blockquote> <p>DataGridViewComboBoxCell value is invalid</p> </blockquote>
    singulars
    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.
 

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