formatting a label control with a date

  • Thread starter Thread starter Brad Allison
  • Start date Start date
B

Brad Allison

Probably a simple question: I have a combobox where the user will select a
member number. I have two labels that are bound to the member's name
(FirstName, LastName). I then have another label that is bound to the
member's date of birth. Everything works fine in that when a member is
selected from the combobox the name changes and the birthdate changes;
however the label for the birthdate is in mm/dd/yyyy format but it also
displays the time of 12:00 am. I want to delete the time. Is there a way
to do this?

Thanks for the information.

Brad

PS This is an oledb data adapter connecting to an access database. The
date field in the database is formatted as short and the date-time picker in
VB is a custom format of MMMM dd, yyyy.
 
Hi Brad,

You should use Format event of DataBinding.
Try something like (C#):

label1.DataBindings["Text"].Format += new ConvertEventHandler(Form1_Format);

private void Form1_Format(object sender, ConvertEventArgs e)

{

e.Value = ((DateTime)e.Value).ToString("d");

}
 
Thanks for the code. Can you convert this code to VB?

Thanks

Miha Markic said:
Hi Brad,

You should use Format event of DataBinding.
Try something like (C#):

label1.DataBindings["Text"].Format += new ConvertEventHandler(Form1_Format);

private void Form1_Format(object sender, ConvertEventArgs e)

{

e.Value = ((DateTime)e.Value).ToString("d");

}


--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

Brad Allison said:
Probably a simple question: I have a combobox where the user will
select
a
member number. I have two labels that are bound to the member's name
(FirstName, LastName). I then have another label that is bound to the
member's date of birth. Everything works fine in that when a member is
selected from the combobox the name changes and the birthdate changes;
however the label for the birthdate is in mm/dd/yyyy format but it also
displays the time of 12:00 am. I want to delete the time. Is there a way
to do this?

Thanks for the information.

Brad

PS This is an oledb data adapter connecting to an access database. The
date field in the database is formatted as short and the date-time
picker
in
VB is a custom format of MMMM dd, yyyy.
 
Hi Brad,

Here you go:
AddHandler Label1.DataBindings("Text").Format, AddressOf Form1_Format

Private Sub Form1_Format(ByVal sender As Object, ByVal e As
ConvertEventArgs)

e.Value = CType(e.Value, DateTime).ToString("d")

End Sub


--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

Brad said:
Thanks for the code. Can you convert this code to VB?

Thanks

Miha Markic said:
Hi Brad,

You should use Format event of DataBinding.
Try something like (C#):

label1.DataBindings["Text"].Format += new ConvertEventHandler(Form1_Format);

private void Form1_Format(object sender, ConvertEventArgs e)

{

e.Value = ((DateTime)e.Value).ToString("d");

}


--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

Brad Allison said:
Probably a simple question: I have a combobox where the user will
select
a
member number. I have two labels that are bound to the member's name
(FirstName, LastName). I then have another label that is bound to the
member's date of birth. Everything works fine in that when a member is
selected from the combobox the name changes and the birthdate changes;
however the label for the birthdate is in mm/dd/yyyy format but it also
displays the time of 12:00 am. I want to delete the time. Is there a way
to do this?

Thanks for the information.

Brad

PS This is an oledb data adapter connecting to an access database. The
date field in the database is formatted as short and the date-time
picker
in
VB is a custom format of MMMM dd, yyyy.
 
Back
Top