Solved

VB.net Binding Controls to BindingSource with Formatting

Posted on 2014-02-06
7
645 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
Comment Utility
0
 

Author Comment

by:spen_lang
Comment Utility
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
Comment Utility
Again, you can use Validating or TextChange event of Textbox.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:spen_lang
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
resolved issue myself
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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