Re: Databinding to user control



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






.



Relevant Pages

  • Re: Databinding to user control
    ... The problem is my control and not the form or the DataSet. ... To work around the issue while binding directly to a DataSet do the ... How do you create a custom user control to be binded to a DataSet so the ... In the title bar is the number of records that have been changed, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Databinding to user control
    ... navigating the data source, ... 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? ... In the title bar is the number of records that have been changed, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Adding records via datagrid
    ... Data binding as a paradigm nicely ... abstraction for generic unbound code involve control naming conventions, ... Again, limitations of the data source object -- if you write your own, ... custom data control to see if I can figure out what you mean. ...
    (microsoft.public.vb.controls)
  • Re: Problem binding ComboBox to a DataTable with a manually added Null row
    ... The point of binding the table to the control is that I don't have to deal ... with a query like "Select Id, Name from States order by CapitalName" (I just ... The wierd thing is that if I bind it to a copy of the table (using ... If I insert the row at the end, then binding has no problem. ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Simple Threading Problem with WinForm
    ... // The delegate to call the method to set the data source. ... including your update of the status bar. ... Also, if you bind to dsLocal.Tables, the data grid will automatically ... > StatusBar control. ...
    (microsoft.public.dotnet.languages.csharp)