Hi all
I'm having a nightmare trying to get this bl**dy DateTimePicker working with DBNull values. I'm almost there, but not quite. Here's my situation.
Within my 'Finances' table are 3 rows, the first which contains a date in 'SettledDate', the second 2 containing null values. What I'm experiencing is:
BUT
I'm confused, and lost!
Any ideas?
Thanks in advance - any help will be gratefully received, trust me!
I'm having a nightmare trying to get this bl**dy DateTimePicker working with DBNull values. I'm almost there, but not quite. Here's my situation.
- I have a service-based database for testing. Within it, it has 2 tables:
- Customers
- Finances - Contains 'CustomerID' as a FK to the relevant column in 'Customers'.
- This table contains the column I'm having problems with - a 'SettledDate' column that allows nulls.
- I have a typed dataset, simply with each of these tables dropped into it - no special SQL query, just a SELECT * in each.
- I have my binding code which is:
C#:
ds = new dsTest();
private void button1_Click(object sender, EventArgs e)
{
dsTestTableAdapters.CustomersTableAdapter Cta = new dsTestTableAdapters.CustomersTableAdapter();
dsTestTableAdapters.FinancesTableAdapter Fta = new dsTestTableAdapters.FinancesTableAdapter();
Cta.Fill(ds.Customers);
Fta.Fill(ds.Finances);
bsCust = new BindingSource(ds, ds.Customers.TableName);
bsFinance = new BindingSource(bsCust, ds.Relations["FK_Cust_Finance"].RelationName);
tb_CustID.DataBindings.Add(new Binding("Text", bsCust, ds.Customers.CustIDColumn.ColumnName));
tb_CustName.DataBindings.Add(new Binding("Text", bsCust, ds.Customers.FullNameColumn.ColumnName));
// Treatments
tb_TotalCost.DataBindings.Add(new Binding("Text", bsFinance, ds.Finances.TotalCostColumn.ColumnName));
cb_Settled.DataBindings.Add(new Binding("Checked", bsFinance, ds.Finances.SettledColumn.ColumnName));
dt_SettledDate.DataBindings.Add(new Binding("Text", bsFinance, ds.Finances.SettledDateColumn.ColumnName));
dt_SettledDate.ValueChanged += new EventHandler(dt_SettledDate_ValueChanged);
}
private void dt_SettledDate_ValueChanged(object sender, EventArgs e)
{
if(dt_SettledDate.Checked == false)
{
dt_SettledDate.Value = dt_SettledDate.MinDate;
dt_SettledDate.Checked = false;
}
}
Within my 'Finances' table are 3 rows, the first which contains a date in 'SettledDate', the second 2 containing null values. What I'm experiencing is:
- When I click the button, the DateTimePicker shows the date contained within the database. I then click my 'Next' button which calls 'bsCust.MoveNext()'.
- At this point, I see the 'MinDate' from my event handler shown above. Clicking next again does the same thing.
- When I eventually go back (calling 'MoveNext()' from my 'Previous' button) from my second record back to my first (that contains an actual date), the date is now not shown, it simply shows the 'MinDate'.
BUT
- I change the 'ShowCheckBox' property on my DateTimePicker control, run the application, try the above again, and now when I change records everything updates as it should - it works as I want and as you would expect. The problem is, I don't want this checkbox shown to the client.
I'm confused, and lost!
Any ideas?
Thanks in advance - any help will be gratefully received, trust me!