ComboBox Control DataSource DataSet/DataTable

Hello,

I am developing a Smart Device Application using Visual Studio 2005 for Windows Mobile 5.0. I have placed a combobox control on one of my Forms. I have written the code that sets the comboBox DataSource equal to a dataSet returned from a private method. Question: whenever I run the application the comboBox is not populated with any data and is blank. I checked my code and everything is correct. I walked through the application in Debug mode and the DisplayMember and ValueMember property of the comboBox are properly declared. After a couple hours of wondering what was wrong I changed the DataSource of the comboBox to a DataTable and the comboBox is now populated with the data. I was under the impression that a DataSet and DataTable were pretty much the same. A DataSet is a group of DataTables. Can anybody offer any suggestions as to why a comboBox works with a DataTable but not a DataSet



Answer this question

ComboBox Control DataSource DataSet/DataTable

  • TaiChiMaster

    No, they are not the same. As you already know DataSet is basically a collection of DataTables, it has no user data inside. That's why if you bind CB to DataSet you would see nothing.

    NETCF V2 supports levels in the binding specifications so you might be able to redirect binding from top level DataSet which has no data to DataTable by using something like “TableName.ColumnName” as DisplayMember/ValueMember.

    However, I would suggest you just bind to DataTable for performance reasons as it contains the data.



  • Somthing Wrong

    Thanks for the insight.
  • Kamarey

    Dear Anthony,

    Just as what Ilya said, you should use dataTable instead of dataSet here.

    The reason is that when you bind a dataset to comboBox, dataset will choose its default view to be binded to your comboBox. Then you set the DisplayMember and ValueMember property of the comboBox, but the value of them may not in the defalut view of your dataset. So nothing will be shown here.

    Regards,

    Zero Dai - MSFT



  • ComboBox Control DataSource DataSet/DataTable