You're selecting only the ProjectNumber string so dgvstrProjectNumbers is Ienumerable<string> (later ToList), and a string does not have 'ProjectNumber' property, no DisplayMember is needed for a string list.
In general when you set DisplayMember do so before assigning the data source.
Why are you setting the DataSource of each cell directly instead of just setting it for the column?
As JohnH suggests, the DisplayMember is supposed to be the name of a property or column in the data source or its items. It is the member of the items to be displayed instead of the result of calling ToString on the items. Your data source is a List<string> and neither that nor its items have a property or column named "ProjectNumber". If you were to bind the source DataTable, then it would make sense to set the DisplayMember, e.g.
is just too vague. You are going through multiple steps so it's important to explain EXACTLY where things are different to what you expect. For a start, does dt_Jobs contain data? If not, what's the point of querying it? Don't just assume that it does. Debug your code and immediately before the LINQ query, test the Rows.Count property of that DataTable.
With regard to my earlier post, I have some data here, but I need to be able to assign some query values (as shown before), to these comboboxes!
From what I have read, I need to populate this information first, and then assign the tableadapterfill, is that correct?
C#:
DataTable dt_Employee = timeDataSet.Tables["Employee"];
DataTable dt_TimeData = timeDataSet.Tables["TimeData"];
DataTable dt_Activity = timeDataSet.Tables["Activity"];
DataTable dt_Jobs = timeDataSet.Tables["Jobs"];
var qryProjectNumbers = from a in dt_Jobs.AsEnumerable()
orderby a.Field<String>("ProjectNumber")
where (a.Field<String>("ProjectNumber") != null)
select a.Field<String>("ProjectNumber");
var lstProjectNumbers = qryProjectNumbers.Distinct().ToList();
// How do I add combobox columns?
DataGridViewComboBoxColumn dgvcboProjectNumbers = (DataGridViewComboBoxColumn)(dgvTime.Columns[6]);
dgvcboProjectNumbers.DataSource = lstProjectNumbers;
this.timeDataTableAdapter1.Fill(this.timeDataSet.TimeData);
When I run the code, I also get this error, though the data for these fields is Nothing. I assume I need to program against null. However, there will be queries defining what this data should be.
Sorry for my rant, but I have been spending about a full week trying to figure out how to write three lines of code.
It is great that ...
C#:
[COLOR=#333333][FONT=Consolas]comboBoxColumn.DisplayMember = "Name";[/FONT][/COLOR]
[COLOR=#333333][FONT=Consolas]comboBoxColumn.ValueMember = "ID";[/FONT][/COLOR]
[COLOR=#333333][FONT=Consolas, Bitstream Vera Sans Mono, Courier New, Courier, monospace]comboBoxColumn.DataSource = myDataTable;
[/FONT]
[FONT=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]But I am having a hard time relating this to the variable of ProjectNumber. I am also wondering where ID even comes in to play. It was my hope to do a query, connvert it to a list, and let those values be the values for by combobox datasource.
Note, in my online searching, this is a common question, but the answers are few.
It does seem that I could just go to my datagridview properties and select columns, and then pan to the ProjectNumber column, which is already a combobox. In there are:
Datasource, DisplayMember and ValueMamber, all None. The Items says Collection, but there is no data there. Wouldnt it just be cool if I could add my query list to the collection here?
I toyed around with changing the datasources, but nothing helped. The fact is, the tables are all setup in the TimeData dataset, pictured in all of my prior posts.
I am so sorry I am not seasoned at this, as I have never done it before. But I'm not so sure it's rocket science. What it shouold be is three or four lines of code. I do believe my query wil work.
What is the ValueMember?
What is the DisplayMember?
I have seen these things identified online, and some people thing one is the other and the other is the one, or vice versa.
Sorry if I have not been clear on this post. I have tried to include as much information as possible.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.