Solved

VB.net Binding Controls to BindingSource with Formatting

Posted on 2014-02-06
7
671 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Icons and Colors for Terms 3 24
Tool Box 2 35
Help with LINQ and XML 10 28
Not seen Link button 5 19
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

25 Experts available now in Live!

Get 1:1 Help Now