Groups | Blog | Home
all groups > dotnet windows forms databinding > may 2005 >

dotnet windows forms databinding : Binding a customized DateTimePicker control and datagrid


v-jetan NO[at]SPAM online.microsoft.com (
5/9/2005 12:00:00 AM
Hi Lynn,

Thanks for your post!!

Based on my understanding, you bind DateTimePicker and DataGrid to the same
datatable, you want to find a way to determine if the DateTimePicker's
selected value is changed. If I misunderstand you, please feel free to tell
me. Thanks

Yes, DataGrid is doing complex databinding with the DataTable, and
DateTimePicker is doing simple databinding with certain Column in
DataTable. Whenever user changes row selection in DataGrid, winform
databinding will keep the index synchronized, and the DateTimePicker's
selected value will change with the selected row value. This by the design
of winform databinding.

For your request, I think we may hook in DateTimePicker.ValueChanged event,
then whenever the selected value is change in DateTimePicker(whatever with
databinding or with user modification), this event will fire, and we can
get notification for this.

Hope this helps.
=========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Lynn
5/9/2005 11:41:05 AM
Hi, I have a situation where I have to bind a DateTimePicker control and a
datagrid to the same data source. In the DateTimePicker.Validated event, I
have to perform certain edit checks. The event fires when the user selects a
date from the calendar. That is fine. However when the user has a row
selected in the datagrid and then tabs out of the grid and into the
DateTimePicker control and then tabs out without making any changes, I don't
want the run my edit checks in the Validated event. Is there a way to
determine if the bound date value has been modified in a date control such as
in the textbox.Modified boolean property? I've attached a snippet of my code
showing what I am trying to do by using the Binding context. However it is
not working. Each time I tab in and out of the control without making any
changes, the row state shows a value of 'modified'. Should I not even be
using the Binding context?

private void customDateTimePicker_Validated(object sender, System.EventArgs e)
{
this.BindingContext[this.dataGrid1.DataSource,
this.dataGrid1.DataMember].EndCurrentEdit();
BindingManagerBase bm=this.BindingContext[this.dataGrid1.DataSource,
this.dataGrid1.DataMember];
DataRowView drv = (DataRowView)bm.Current;
DataRow dr = drv.Row;
MessageBox.Show ("RowState " + dr.RowState.ToString());

}

Thanks,
Lynn
5/10/2005 6:36:01 AM
Hi Jeffrey, the DateTimePicker.ValueChanged event will not work in my
situation. I have certain edits that I need to perform when a new date is
selected. For example, one of edits is to set the
MinDate=System.DateTime.Now whenever a user selects a date. I want to apply
this edit only when the user selects a new date. However if the user is just
navigating through existing records in the datagrid, I don't want to subject
the existing dates to this restriction.

For example: MinDate=System.DateTime.Now
1. (DataGrid:Record#1) - date is 05/01/05
- if the user navigates to this row, the MinDate restriction is not
applicable.
- if the user selects a new date or modifies an existing date, then the
MinDate restriction is applicable

I am struggling to find an event that could properly handle my situation. I
had mentioned about the TextBox.Modified property because I was hoping to
find something similar in the DateTimePicker to let me know when a value has
truly been modified. Currently I am putting my edits in the
DateTimePicker.Validated event. This event works correctly for my purpose if
the user uses the mouse to select a date from the calendar. However if the
user tabs through the DateTimePicker control without making a change the
Validated event still fires causing the date value to go through the same
edits as if it was a newly selected date. I hope I was able to clearly state
my problem.

[quoted text, click to view]
v-jetan NO[at]SPAM online.microsoft.com (
5/11/2005 1:13:57 AM
Hi Lynn,

I think this issue is almost the same with your another issue "How to set
MaxDate on the DateTimePicker". I have added a reply to you in that issue,
please check it there, I will follow up with you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
AddThis Social Bookmark Button