Displaying DataSet default values in a new form
Posted on 2006-05-16
I think this is quite a simple question but for some reason I am not getting answers in other forums and I need help urgently. Anyway, I am sure somebody here can help.
Using Visual Basic 2005 Express, I am wanting to display data in a Windows form from a typed DataSet that displays only one record of XML data. I have not provided an XML file as yet as I want my form to initially just display the default column values I provided when creating the DataSet in the DataSet Designer. The problem is the default data is not displaying and all the controls are blank. I am obviously missing a step.
I have followed the process below...
1. Created a typed DataSet using the DataSet Designer, added a DataTable and columns and set the columns default values. Set the AllowNew property of the BindingSource to false. Added the DataSet to the Data Sources list window.
2. Created a simple Windows test form with 1 textbox and 1 combo box.
3. Dragged the relevant data source items from the Data Sources window onto the controls on the relevant form controls.
I expect when I run the program the controls will display the default values provided for the columns in the DataSet, however, they are blank.
I suspect it might be because, as the MSDN reference says, default column values are displayed when a new record is added and I am not actually adding any new records but just loading the form (wanting the defaults to be displayed initially at form load) but I may be wrong on this.
I ultimately want the user to be able to start each form in my application with the default values already on the form when it loads, and to be able to edit the default data and then save the data to a new XML file.
Can I get the default column values to display in the databound controls as soon as a new form is loaded?
(For those not used to the DataSet Designer in VS.NET 2005 - the default column values translate to default element attributes in the W3C Schema describing the DataSet, so the question becomes can the DataSet simply be created with default values pre-generated from the schema defaults? )
Thanks for your help.