473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

set custom date format for bound textbox?

Hello,

I have some datefields in a dataset (ds1). I bind some
textbox controls on a windows form to these date fields in
ds1, but I only want to see 01/01/2004 instead of 1/1/2004
8:00:00 AM. In a DateTimePicker control I can set a
custom format("MM/dd/yyyy"). So when I iterate through
ds1 with currency manager (cma) I see the correct date
format in a DateTimePicker control. Is it possible to set
a custom date format like that for a bound textbox
control? I realize that for every event where I could
increment cma I could say txtDate.Text = Format(ds1....)
but that kind of defeats the idea of a bound textbox. Is
there a way to set a custom format for a textbox like on
the form_load evnet?

Thanks,
Rich
Nov 20 '05 #1
1 9381
Cor
Hi Rich,

I made a sample for you, but did not test it.

Can you try it and tell me if it is complete, than I can use it the next
time as sample and not have to write the sentence above?

(The date is in EU format of course so you have to change that to US)

Cor

\\\
Private Sub myroutine()
Mybinding = New Binding("Text", ds.Tables(0), "mydatfield")
textdatfield.DataBindings.Add(Mybinding)
AddHandler mybinding.Format, AddressOf DBdateTextbox
AddHandler mybinding.Parse, AddressOf TextBoxDBdate
End sub
Private Sub DBdateTextbox(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
cevent.Value = datum.ToString("dd - MM - yyyy")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
End If
End Sub
///

I have some datefields in a dataset (ds1). I bind some
textbox controls on a windows form to these date fields in
ds1, but I only want to see 01/01/2004 instead of 1/1/2004
8:00:00 AM. In a DateTimePicker control I can set a
custom format("MM/dd/yyyy"). So when I iterate through
ds1 with currency manager (cma) I see the correct date
format in a DateTimePicker control. Is it possible to set
a custom date format like that for a bound textbox
control? I realize that for every event where I could
increment cma I could say txtDate.Text = Format(ds1....)
but that kind of defeats the idea of a bound textbox. Is
there a way to set a custom format for a textbox like on
the form_load evnet?

Thanks,
Rich

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: J. Muenchbourg | last post by:
while inserting new records into SQL, i'm using the folloinwg sqlstatement> Dim MySQL as string = "Insert into roster (pname, pnotes, thedate) values (@pname, @pnotes, @thedate)" the sql...
2
by: Matt | last post by:
I have a number of TextBox controls bound to date fields in my application, and have come across a disconcerting issue: When you are entering data into the bound field, if you enter any string that...
2
by: Derek Vincent | last post by:
What must I do to overcome a problem with my dates becoming formatted as "2/22/2525 12:00:00 AM" in the datagrid? I want to handle all dates as short string of format "2/22/2525." Otherwise when I...
2
by: Drum2001 | last post by:
Hello, I am having isues with the following: I have two forms, a MAIN FORM with a SUB FORM: Within the MAIN FORM, I have an unbound textbox (Date Format) and a command button. Onload, the...
2
by: paulquinlan100 | last post by:
Hi I have a bound form that displays a whole load of dates, in several of these i would like to be able to show "TBC" rather than a blank field. I'm guessing i could store a date in the fields...
4
by: Allen Browne | last post by:
Paul, you *really* need to head Stuart's advice. The data types are crucially important in database fields. Non-date values (like the 3 letters TBC) are not valid dates, and cannot be evaluated...
1
by: JFKJr | last post by:
Hello everyone, this one might be simple but driving me crazy! Your help will be greatly appreciated. Basically, I created a textbox bound to "Date" field in an Access VBA form. But when the...
6
by: =?Utf-8?B?QmVu?= | last post by:
All - I have VB2008. On the form I have a date picker and a text box. I put would like to display a date format in the form of "MM-DD-YYYY" or "MM-YYYY" I am new to vb2008, can you show me...
3
by: EdisonCPP | last post by:
Hi, I have a DetailsView with a template field with a dropdownlist added to it. If the data coming into that field were put into a textbox, it would look like: Small|Medium|Large|X-Large. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.