Note that there are some explanatory texts on larger screens.

plurals
  1. PODataGridViewComboBoxColumn does not allow me to select an object from a list
    primarykey
    data
    text
    <p>I have a DataGridView which allows the user to add a new object to a list. One of the important parts of this is to select the type from a user-definable list.</p> <p>I am defining the columns like so:</p> <pre><code>this.DataGridView.Columns.Add(new DataGridViewComboBoxColumn { Name = "Resource", DataPropertyName = "Resource", DataSource = new BindingSource { DataSource = this.Document.Resources }, ValueType = typeof(Resource), DisplayMember = "Name" }); </code></pre> <p>I then set the DataSource of the DataGridView to the list of UserResources:</p> <pre><code>BindingList&lt;UserResource&gt; relatedResources = new BindingList&lt;UserResource&gt;(this.User.ResourcesRequired); this.DataGridView.DataSource = relatedResources; </code></pre> <p>The Resource class layout looks like this:</p> <pre><code>public class Resource { public string Name { get; set; } public string Description { get; set; } public int InitialLevel { get; set; } } </code></pre> <p>The UserResource class looks like this:</p> <pre><code>public class UserResource { public Resource Resource { get; set; } public int CurrentLevel { get; set; } </code></pre> <p>The User class looks like this:</p> <pre><code>public class User { public string Name { get; set; } public IEnumerable&lt;UserResource&gt; Resources { get; set; } } </code></pre> <p>I can see a list of available Resource types, but the item that is selected in the DataGridViewComboBoxCell does not stay selected. After selecting the item, when I move on to the next field, the DataGridViewComboBoxCell clears itself.</p> <p>Other fields in the row will be written to my new UserResource instance, but the Resource reference will not be saved, and the property remains null on the new UserResource instance.</p> <p>In case people are wondering, I am not using any sort of object relational mapper or any sort of database layer at all. All objects in memory are written to and read from an XML document.</p> <p>I'm honestly unsure about how to continue debugging this issue from here. Does anybody have any recommendations?</p>
    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.
 

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