Solved

VB.net Binding Controls to BindingSource with Formatting

Posted on 2014-02-06
7
732 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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