databing to datagrid with drop down list

databing to datagrid with drop down list

Old forum URL: forums.lhotka.net/forums/t/3500.aspx


jhw posted on Sunday, September 09, 2007

I want to databind  an editable object to a datagridview, with 1 of the columns being a drop down combobox. This is similar to what Rocky does with his project edit  windows control example in bus objs 2005.

I have an editable city list. The city objects have an associated province. When i display this in the grid, I want the provinces to be displayed in the drop down combobox. When I try to set the datasource for the the combobox in the columns edit dialog, it tells me "object not set to an instance".  Of course in the example Rocky shows, the binding source control shows up in the datasoure property. I can't find a way of getting my provinces binding control to show up in the datasource property.

I am currently building a workaround to this manually, but it would be great if it would work the way it does in the book so I would not have to populate the combobox manually and manually handle events to set the province.

 

Thanks

Heath

RockfordLhotka replied on Sunday, September 09, 2007

Windows Forms right?

You do need to add the object as a data source. You can do that in the Data Sources window ahead of time, or there's an option to add the object as a data source in the data source selection process. I don't recall the specific terminology they use, but it is possible directly in that drop-down where you get to select from the existing data sources.

Either way, once it is a valid data source, when you use it to configure your column, Visual Studio will automatically add the appropriate bindingsource object to your form.

jhw replied on Monday, September 10, 2007

Yes it is a windows foms control.

I must be having problems with visual studio as I do have all my objects added as datasources.

 

After I drag a collection on, the datagrid and binding source are automatically added. If I go to properties of either of the controls, I have the same problem. Even though the datasource is already set, I still get the object not set to an instance error if I click the drop down error for that datasource. So far google has not helped. Has anyone had this problem?

 

Heath

jhw replied on Monday, September 10, 2007

I found the problem. When I checked out the datasources for my project, there was 1 listed that was marked with a warning. When I removed that item, everything started working.

 

Heath

Copyright (c) Marimer LLC