?
Solved

automatically add a record with binding navigator

Posted on 2006-05-12
6
Medium Priority
?
329 Views
Last Modified: 2012-06-27
i have a form which has a binding navigator. when the form loads, i still have to click on the ADD RECORD button to start it off. i would like to have it add automatically on form load event.
also, there is a textbox bound to the dataset, e.g. column CustomerID. i need to set this textbox to a number everytime i add a new record. the number could be a GUID, or anything unique, but i need to add a different one for every record that i add. where should i put the code to to that?

both questions relate to each other somehow (the adding of records part).

thanks
0
Comment
Question by:newyuppie
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:vadim63
ID: 16669268
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       ' TableAdapter.Fill(DataSet.Table)
        BindingSource.AddNew()    
End Sub
0
 
LVL 13

Author Comment

by:newyuppie
ID: 16669352
great. now, how can i check if no data is on the table then addnew(), else don't.
and how can i set the default value of a textbox (bound to a column in the datatable) to be a GUID that is different everytime i addnew()?
thanks for your responses.
0
 
LVL 10

Expert Comment

by:vadim63
ID: 16669402
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TableAdapter.Fill(DataSet.Table)
        If BindingSource.Count = 0 Then BindingSource.AddNew()
 End Sub

And set the "AutoIncrement" propertie of your "GUID" column to "true"
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 13

Author Comment

by:newyuppie
ID: 16669590
problem is the column is of String values. i just want to set it to a GUID which i would like to generate runtime. ideally, i would like to behave like this

Private Sub SolicitantesBindingSource_AddedNew(ByVal sender As Object, ByVal e As System.ComponentModel.AddingNewEventArgs) Handles SolicitantesBindingSource.AddingNew

currentposition.column("CustomerID").value = system.guid.generatenewguid.tostring

    End Sub

of course this doesnt exist, but it shows the logic im looking for.
by the way thanks for the other answers they work fine.
0
 
LVL 10

Accepted Solution

by:
vadim63 earned 1000 total points
ID: 16669669
Why don't you set it as integer? It's very simple way.
0
 
LVL 13

Author Comment

by:newyuppie
ID: 16669877
thats my last resort yes... i just figured i could use the answer to this problem to generate codes, not only guid, but if i wanted i would use CUST001, CUST002, or something autoincrementing like that but not necesarilly integer.
thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month16 days, 20 hours left to enroll

862 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