DateTimePicker control with the BindingNavigator Toolbar

B

Blue Stallion

I am creating a form that has a DateTimePicker control that is bound to a
DateTime field in a SQL Server database. When I step through the records in
the database by using the next and previous buttons on the toolbar the
DateTimePicker control does not always show the correct data. If the
DateTime field in the database has an entry it will be displayed, however, if
the field is null, the data from the previous record is displayed. If the
next or previous button is clicked with the erroneous data displayed, it is
now remember and stored with the record. I have read in other threads that
the DateTimePicker control has problems with nulls. Is there something I can
put in the next and previous buttons click methods that would clear out the
data from the previous record before showing the new current record, where
the field would be null (not checked) if the new current field is null, or
display the new current data, if available?

I am using C# 2005 in Visual Studio 2005

Thanks,
 
B

Blue Stallion

Thanks for the reply. I have been trying different things wiht the Format
event today, but I'm not getting the desired results. Here is my last
attempt to get the Format event to replace null values with the MinValue when
the First, Prev, Next, or Last button is clicked on teh nav bar:

public partial class ActualFiringPositions : Form
{
public ActualFiringPositions()
{
InitializeComponent();

Binding b = new Binding("Text", firingPositionsBindingSource,
"ActualDate");
b.Format += new ConvertEventHandler(b_Format);
//b.Parse += new ConvertEventHandler(b_Parse);
actualDateDateTimePicker.DataBindings.Add(b);
}
void b_Format(Object sender, ConvertEventArgs cevent)
{
if (cevent.Value == DBNull.Value)
{
cevent.Value = System.DateTime.MinValue;
}
}
void b_Parse(Object sender, ConvertEventArgs cevent)
{
MessageBox.Show("in Parse"); // Had not gotten this far yet
}
 
C

Cor Ligthert[MVP]

For sure is the property to bind to a DateTimePicker the value of that.
(I assume the field is in the database as well a DateTime field)

Do you have it maybe binded already using the designer?

Cor
 
B

Blue Stallion

The form was built by dragging the table to a new form, so everything was
built by the designer. All I really did was arrangee the controls in a
logical manner. So whatever bindings there are were built by the designer.
I reviewed the links for Format and Parse that you sent, but since the
examples were for a text field, I'm not sure that I correctly made the
changes needed. When I do the binding for Text it will compile. If I change
the binding to Value it complains about it being bound twice. Yes, the
database field is a date time field. Being kinda new C# and Visual Studio
2005, I'm at a loss of what to try next.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top