Solved

VB.net Binding Controls to BindingSource with Formatting

Posted on 2014-02-06
7
683 Views
Last Modified: 2014-02-18
Hi,

I am creating a database application and have bound my form controls to the binding source.

One of the form controls is a DateTimePicker and the DataBinding is:
dtpickerDate.DataBindings.Add("Value", bsReading, "Reading_Date", True, DataSourceUpdateMode.OnValidation, DateTime.Today)

Open in new window


How can I format the DataBinding so that when the value is sent back to the database it does not include the current timestamp or the current timestamp is set to 00:00:00.

I am using a DataAdapter to to insert/update the data.

Thanks, Greg
0
Comment
Question by:spen_lang
  • 4
  • 3
7 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39838458
0
 

Author Comment

by:spen_lang
ID: 39839312
Hi,

Another formatting issue with a bound textbox, I would like to format the following as two decimal palces (rounded up).

How can I achieve this?

 txtUsage_TTM_CostDaily.DataBindings.Add("Text", bsUsage, "TTM_AvgDailyCost")

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39839692
Again, you can use Validating or TextChange event of Textbox.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:spen_lang
ID: 39841274
Hi,

I have tried the following code:
Private Sub txtUsage_InServ_CostDaily_TextChanged(sender As Object, e As System.EventArgs) Handles txtUsage_InServ_CostDaily.TextChanged
        txtUsage_InServ_CostDaily.Text = Convert.ToInt32(txtUsage_InServ_CostDaily.Text)
    End Sub

Open in new window


but I get an error, "Input string was not in a correct format."
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39842681
What does the textbox contain when you this code runs?

Try

Private Sub txtUsage_InServ_CostDaily_TextChanged(sender As Object, e As System.EventArgs) Handles txtUsage_InServ_CostDaily.TextChanged
If Not String.IsNullOrEmpty(txtUsage_InServ_CostDaily.Text) Then
        txtUsage_InServ_CostDaily.Text = Convert.ToInt32(txtUsage_InServ_CostDaily.Text)
End If
    End Sub

Open in new window

0
 

Accepted Solution

by:
spen_lang earned 0 total points
ID: 39843824
I have found out that you can setting the format when you bind the text box using
txtUsage_InServ_Cost.DataBindings.Add("Text", bsUsage, "RunningTotal_Cost", True, DataSourceUpdateMode.Never, vbNullString, "c5")

Open in new window

0
 

Author Closing Comment

by:spen_lang
ID: 39866932
resolved issue myself
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 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