Displaying DataSet default values in a new form

Posted on 2006-05-16
Last Modified: 2010-04-23
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.
Question by:mjtech
    LVL 34

    Accepted Solution

    Can I get the default column values to display in the databound controls as soon as a new form is loaded?

    If the controls are bound, no, unless you are prepared to add a new record.  The default value sets the values for a new record, not the controls.  The controls are bound to a record.  If there is no record in the datasource, there is nothing to display.  If there is a new record in the datasource, there are the default values to display.  So you can either break the bindings and put the values you want directly into the controls.  Or you can go down the "create new record" route.  I wonder what is wrong with the latter.  If the user decides s/he doesn't want to proceed with creating (i.e. editing) the new record you produced for display purposes, you can always junk it.

    LVL 1

    Author Comment

    Thanks, Roger.

    I don't have any objections to your latter approach. I was curious if there was something I was missing or mistaking as I am new to .NET.

    So just to confirm I understand you, the best route in your opinion is to add new record programmatically which will cause the default column values to be displayed in the form?


    LVL 34

    Expert Comment

    Yes, that's what I meant.

    LVL 1

    Author Comment

    Well I just tried the above and it works fine so thanks for your help, Roger! :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now