Re: Databinding to user control
- From: "John J. Hughes II" <no@xxxxxxxxxxx>
- Date: Mon, 26 Jun 2006 17:45:39 -0400
Hello again,
Ok the following change seems to mostly fix the problem. Changing rows does
not change the number of rows changed and if the data is changed the DataSet
fetches the data correctly. It does not report the data as change but I
think I am on the correct path.
public partial class UserControl1 : UserControl, INotifyPropertyChanged
Regards,
John
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:OV37lFWmGHA.4536@xxxxxxxxxxxxxxxxxxxxxxx
Hi John,
I just had some time to look at the code you attached.
The DataGridView.SelectionChanged method seems to be raised in the middle
of navigating the data source, not after navigation is complete. To be
honest I don't know why this is happening on that particular event but it
seems that the DataGridView does in fact change the state of a DataRow
while navigating the DataSet, however the changes are lost after
navigation is complete. Perhaps binding to a BindingSource object instead
will alleviate the problem.
To work around the issue while binding directly to a DataSet do the
following:
1. Remove your DataGridView.SelectionChanged event handler
2. Place the following line of code at the end of the Form.Load event
handler:
((CurrencyManager) this.BindingContext[dataSet1, "Table1"]).ListChanged
+= new ListChangedEventHandler(Form1_ListChanged);
3. Create the following event handler for the ListChanged event of your
data source:
private void Form1_ListChanged(object sender, ListChangedEventArgs e)
{
this.DisplayChangeCount();
}
Using the ListChanged event of the CurrencyManager for the Form will
ensure that the TitleBar is only updated when 'real' changes occur to the
DataSet.
HTH
"John J. Hughes II" <no@xxxxxxxxxxx> wrote in message
news:%23SXGZEVmGHA.508@xxxxxxxxxxxxxxxxxxxxxxx
Dave,
Thank you for your patience.
One line question (don't think it will help):
How do you create a custom user control to be binded to a DataSet so the
DataSet knows when the data used by the control is updated?
*****************************************************
Reboot... attached find a small project to demo my problem. (VS2005)
When run the main form show a DataGridView which shows the first column
of several records. To the right is two controls, one is a rich text
box and the other is my custom control. At this point the custom
control does not do anything expect display the size, later it will need
to modify the data (another topic).
In the title bar is the number of records that have been changed, at this
point we don't care about saving the data.
Now in my opinion as I move up and down though the rows the title bar
value should always show -0- unless something is edited.
If you comment out the follow line the title bar will always show -0- but
if the line is not commented out then each time the row is changed the
title bar increments by one.
/// Title bar changes count
public Form1()
{
InitializeComponent();
this.userControl11.DataBindings.Add(new
System.Windows.Forms.Binding("MsgData", this.dataSet1, "Table1.Data",
false));
}
/// Title bar does not change count
public Form1()
{
InitializeComponent();
/// this.userControl11.DataBindings.Add(new
System.Windows.Forms.Binding("MsgData", this.dataSet1, "Table1.Data",
false));
}
**************************************************
Note in the project is a second custom user control which uses a string
instead of a byte array. If this is used in place of the rich text
control then the records change each time the row changes. I have
concluded from this that the binding does not compare the value but is
using some other method to determine the value has changed.
Regards,
John
.
- Follow-Ups:
- Re: Databinding to user control
- From: John J. Hughes II
- Re: Databinding to user control
- References:
- Databinding to user control
- From: John J. Hughes II
- Re: Databinding to user control
- From: Dave Sexton
- Re: Databinding to user control
- From: John J. Hughes II
- Re: Databinding to user control
- From: Dave Sexton
- Re: Databinding to user control
- From: Dave Sexton
- Databinding to user control
- Prev by Date: RE: Singleton & Interfaces
- Next by Date: Re: Transferring a lot of data
- Previous by thread: Re: Databinding to user control
- Next by thread: Re: Databinding to user control
- Index(es):
Relevant Pages
|