Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Displaying DataSet default values in a new form

Posted on 2006-05-16
4
Medium Priority
?
267 Views
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.
0
Comment
Question by:mjtech
  • 2
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 240 total points
ID: 16689850
>>
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.

Roger
0
 
LVL 1

Author Comment

by:mjtech
ID: 16690083
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?

Thanks.


0
 
LVL 34

Expert Comment

by:Sancler
ID: 16690217
Yes, that's what I meant.

Roger
0
 
LVL 1

Author Comment

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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

581 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