Re: Databinding to user control



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
    ... 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 ... 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: 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: 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)
  • Re: Disymmetry of lift.....
    ... "stabilizer" bar. ... The bar has a percentage ... Someone came up with the idea of mixing a direct control link ... The result was a more crisp response to a given cyclic command ...
    (rec.models.rc.helicopter)
  • Re: How does the divided bar work?
    ... I have asked that the ungroup warning be scarier. ... subshapes can reference the group shape or each other. ... The group shape has a two control handles to manipulate the two ... that divides the width of the bar by the width of the grouped shape. ...
    (microsoft.public.visio.general)

Quantcast