Sometimes, I usually create a class with the type of data I want like this:
public class message{
private string subject { get; set; }
private string message { get; set; }
}
This way, I can bind a List<message> to a datagrid and change the DataPropertyName.
However, if I happen to add more auto properties to this class, my datagrid starts to misbehave and sometimes I don’t just want some of the properties to the datagrid. Is there anyway I can bind the datagrid to only the values I selected DataPropertyName for?
Thanks.
If you don’t want extra columns in your datagrid, why not start with your query, and don’t list them in the SELECT clause. This has the added benefit of reducing network traffic.
Create multiple queries or views off the same table and use the right one at the right timefor your need. This is the “upstream” solution.
Alternatively,
That is straight from MSDN, you should have researched a little more thoroughly before posting this.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.datapropertyname.aspx