473,746 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databinding to user control

I have a DataGridView displaying data from a DataSet. To the right of that
I have a custom user control which displays one of the data set fields.
The custom user control is bound to the data set object and displays the
data correctly when I move from row to row.

The problem I am having is the data set always reads the data back and
considers it change even when it's not. I am looking for how to change the
following code so the custom user control can set the pencil on the
DataGridView and only cause the data set to be updated if the data is
changed. I don't want to host the control in the DataGridView.

Since I do this with RichTextControl s I am assuming its the way I am doing
it and possible.

My guess is I need to enable PropertyChange or Validated but neither work so
obviously I am doing it incorrectly.

//// The data binding in the main form
//// This version uses OnPropertyChang ed and I have tried OnValidation.
//
// ctrlMsgEditor1
//
this.ctrlMsgEdi tor1.Cursor = System.Windows. Forms.Cursors.D efault;
this.ctrlMsgEdi tor1.DataBindin gs.Add(new
System.Windows. Forms.Binding(" MsgData", this.dsMsg1, "Messages.Data" , true,
System.Windows. Forms.DataSourc eUpdateMode.OnP ropertyChanged) );
this.ctrlMsgEdi tor1.Dock = System.Windows. Forms.DockStyle .Right;
this.ctrlMsgEdi tor1.Location = new System.Drawing. Point(306, 0);
this.ctrlMsgEdi tor1.MsgData = null;
this.ctrlMsgEdi tor1.Name = "ctrlMsgEditor1 ";
this.ctrlMsgEdi tor1.Size = new System.Drawing. Size(347, 328);
this.ctrlMsgEdi tor1.TabIndex = 7;

//// The custom user control
[System.Componen tModel.DefaultB indingProperty( "MsgData")]
public partial class ctrlMsgEditor : UserControl
{
private byte[] _MsgData = new byte[1];
[System.Componen tModel.Bindable (true), Browsable(true) ,
Category("Data" ), Description("En coded data to be displayed")]
public byte[] MsgData
{
get
{
lock (this)
{
return _MsgData;
}
}
set
{
lock (this)
{
this._MsgData = value;
this.DisplayDat a(this._MsgData );
}
}
}
public ctrlMsgEditor()
{
InitializeCompo nent();
}

private void DisplayData(byt e[] msgData)
{
/// Display the data
}
}
Regards,
John
Jun 25 '06 #1
11 11574
Hi John,

What do you mean, "The data set always reads the data back and considers it
change event when it's not."?

The DataGridView handles the state of row changes correctly in my
experience. DataRows being displayed by a DataGridView are always in an
Unchanged, Modified, Deleted or Added state. While editing a row in the
DataGridView the state of the underlying DataRow remains Unchanged until the
changes are committed by the user, in which case the DataRow becomes
Modified.

Could you possibly have forgotten to call DataSet.AcceptC hanges() after you
filled the data? (Calling AcceptChanges() isn't necessary when using a
DataAdapter with the default settings)

BTW, the locks in your get and set accessors for the MsgData property aren't
serving any purpose. Locking the "return" statement is of no use and the
variable assignment and method call should probably not be locked and just
allow race conditions in an asynchronous environment. Also, since it's a
UserControl you'll probably have to call Invalidate to update the display
when MsgData is set so synchronicity will be handled implicitly by the
framework on the UI Thread.

HTH

"John J. Hughes II" <no@invalid.com > wrote in message
news:eH******** ******@TK2MSFTN GP04.phx.gbl...
I have a DataGridView displaying data from a DataSet. To the right of
that I have a custom user control which displays one of the data set
fields. The custom user control is bound to the data set object and
displays the data correctly when I move from row to row.

The problem I am having is the data set always reads the data back and
considers it change even when it's not. I am looking for how to change
the following code so the custom user control can set the pencil on the
DataGridView and only cause the data set to be updated if the data is
changed. I don't want to host the control in the DataGridView.

Since I do this with RichTextControl s I am assuming its the way I am doing
it and possible.

My guess is I need to enable PropertyChange or Validated but neither work
so obviously I am doing it incorrectly.

//// The data binding in the main form
//// This version uses OnPropertyChang ed and I have tried OnValidation.
//
// ctrlMsgEditor1
//
this.ctrlMsgEdi tor1.Cursor = System.Windows. Forms.Cursors.D efault;
this.ctrlMsgEdi tor1.DataBindin gs.Add(new
System.Windows. Forms.Binding(" MsgData", this.dsMsg1, "Messages.Data" ,
true, System.Windows. Forms.DataSourc eUpdateMode.OnP ropertyChanged) );
this.ctrlMsgEdi tor1.Dock = System.Windows. Forms.DockStyle .Right;
this.ctrlMsgEdi tor1.Location = new System.Drawing. Point(306, 0);
this.ctrlMsgEdi tor1.MsgData = null;
this.ctrlMsgEdi tor1.Name = "ctrlMsgEditor1 ";
this.ctrlMsgEdi tor1.Size = new System.Drawing. Size(347, 328);
this.ctrlMsgEdi tor1.TabIndex = 7;

//// The custom user control
[System.Componen tModel.DefaultB indingProperty( "MsgData")]
public partial class ctrlMsgEditor : UserControl
{
private byte[] _MsgData = new byte[1];
[System.Componen tModel.Bindable (true), Browsable(true) ,
Category("Data" ), Description("En coded data to be displayed")]
public byte[] MsgData
{
get
{
lock (this)
{
return _MsgData;
}
}
set
{
lock (this)
{
this._MsgData = value;
this.DisplayDat a(this._MsgData );
}
}
}
public ctrlMsgEditor()
{
InitializeCompo nent();
}

private void DisplayData(byt e[] msgData)
{
/// Display the data
}
}
Regards,
John

Jun 25 '06 #2
Well obviously I did not make myself clear. There is nothing wrong with
the dataset and it is working just fine. The problem is the way I have
written my control. When row is selected in the data grid view my custom
control displays one of the columns correctly via the data binding using the
MsgData set property. When the row is changed the new row is also displayed
correctly. The problem is every time the row is changed the MsgData is
read using get and the DataSet considers it changed. So if I do a
dataset.GetChan ges() every row viewed reports changes made when no changes
were made. In fact currently the control does not allow changes and
whatever is set is return.

I assume there is some method which I have not found to cause the DataSet to
be notified that the data in the control is being edit. If I do the same
thing but use a string and text field the DataSet does not consider the data
changed just by changing rows but does apply the changes and mark the
DataSet as changed when the text in the control is updated.

Mind you the problem might lay in the DataSet being unable to determine if
the data has changed being its a byte array. If so do I need to supply a
special object to deal with the comparison. I tried using the
IEditableObject to but was unsuccessful.

Thanks for the information on locks.

Regards,
John
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:uB******** ******@TK2MSFTN GP05.phx.gbl...
Hi John,

What do you mean, "The data set always reads the data back and considers
it change event when it's not."?

The DataGridView handles the state of row changes correctly in my
experience. DataRows being displayed by a DataGridView are always in an
Unchanged, Modified, Deleted or Added state. While editing a row in the
DataGridView the state of the underlying DataRow remains Unchanged until
the changes are committed by the user, in which case the DataRow becomes
Modified.

Could you possibly have forgotten to call DataSet.AcceptC hanges() after
you filled the data? (Calling AcceptChanges() isn't necessary when using
a DataAdapter with the default settings)

BTW, the locks in your get and set accessors for the MsgData property
aren't serving any purpose. Locking the "return" statement is of no use
and the variable assignment and method call should probably not be locked
and just allow race conditions in an asynchronous environment. Also,
since it's a UserControl you'll probably have to call Invalidate to update
the display when MsgData is set so synchronicity will be handled
implicitly by the framework on the UI Thread.

HTH

"John J. Hughes II" <no@invalid.com > wrote in message
news:eH******** ******@TK2MSFTN GP04.phx.gbl...
I have a DataGridView displaying data from a DataSet. To the right of
that I have a custom user control which displays one of the data set
fields. The custom user control is bound to the data set object and
displays the data correctly when I move from row to row.

The problem I am having is the data set always reads the data back and
considers it change even when it's not. I am looking for how to change
the following code so the custom user control can set the pencil on the
DataGridView and only cause the data set to be updated if the data is
changed. I don't want to host the control in the DataGridView.

Since I do this with RichTextControl s I am assuming its the way I am
doing it and possible.

My guess is I need to enable PropertyChange or Validated but neither work
so obviously I am doing it incorrectly.

//// The data binding in the main form
//// This version uses OnPropertyChang ed and I have tried OnValidation.
//
// ctrlMsgEditor1
//
this.ctrlMsgEdi tor1.Cursor = System.Windows. Forms.Cursors.D efault;
this.ctrlMsgEdi tor1.DataBindin gs.Add(new
System.Windows. Forms.Binding(" MsgData", this.dsMsg1, "Messages.Data" ,
true, System.Windows. Forms.DataSourc eUpdateMode.OnP ropertyChanged) );
this.ctrlMsgEdi tor1.Dock = System.Windows. Forms.DockStyle .Right;
this.ctrlMsgEdi tor1.Location = new System.Drawing. Point(306, 0);
this.ctrlMsgEdi tor1.MsgData = null;
this.ctrlMsgEdi tor1.Name = "ctrlMsgEditor1 ";
this.ctrlMsgEdi tor1.Size = new System.Drawing. Size(347, 328);
this.ctrlMsgEdi tor1.TabIndex = 7;

//// The custom user control
[System.Componen tModel.DefaultB indingProperty( "MsgData")]
public partial class ctrlMsgEditor : UserControl
{
private byte[] _MsgData = new byte[1];
[System.Componen tModel.Bindable (true), Browsable(true) ,
Category("Data" ), Description("En coded data to be displayed")]
public byte[] MsgData
{
get
{
lock (this)
{
return _MsgData;
}
}
set
{
lock (this)
{
this._MsgData = value;
this.DisplayDat a(this._MsgData );
}
}
}
public ctrlMsgEditor()
{
InitializeCompo nent();
}

private void DisplayData(byt e[] msgData)
{
/// Display the data
}
}
Regards,
John


Jun 26 '06 #3
Hi John,

I tried to piece together your problem from snippets of your last post. I
have responded to each snippet inline, below. If you could possibly
condense your question into one line, if I haven't answered it in this post,
it would be much easier to answer.
When the row is changed the new row is also displayed correctly. The
problem is every time the row is changed the MsgData is read using get and
the DataSet considers it changed.
Sounds correct to me. If you change a field value in a DataRow the
DataRow.RowStat e property will become "Modified". The DataSet does not
consider a DataRow changed just by reading a value.
So if I do a dataset.GetChan ges() every row viewed reports changes made
when no changes were made.
If you want to commit all changes to a DataSet so that GetChanges() returns
null simply call DataSet.AcceptC hanges(). Editing the DataRow in the
DataGridView will cause GetChanges() to return changed DataRows until
DataSet.AcceptC hanges() is called. If DataSet.GetChan ges() returns null
before the data is bound to a DataGridView it will remain null until a
DataRow is edited and the changes are committed. DataSet.AcceptC hanges()
should be called immediately after the DataSet is filled with data, unless
your using a DataAdapter or table adapter will the default settings.
In fact currently the control does not allow changes and whatever is set
is return
Do you mean to say that your control does not provide a way for users to
edit the bound data? The DataSet will not mark a DataRow as "Modified"
because it is bound to a control, it will only mark a DataRow as "Modified"
if the value is changed. Reading a value does not qualify as changing a
value. If you don't provide code in your control that changes the value of
a column in a bound DataRow then the DataRow.RowStat e will remain
"Unchanged" until the data is edited and committed or the row is deleted.
I assume there is some method which I have not found to cause the DataSet
to be notified that the data in the control is being edit
DataRow.BeginEd it()
DataRow.EndEdit ()
DataRow.CancelE dit()
If I do the same thing but use a string and text field the DataSet does
not consider the data changed just by changing rows but does apply the
changes and mark the DataSet as changed when the text in the control is
updated.
Navigating the bound DataSet of a DataGridView will not cause the DataSet to
change the state of one of its DataRows. The value of a DataColumn for a
DataRow must be edited. I suspect that if you are simply navigating the
DataSet by selecting a row in the DataGridView and then detecting changes
using the GetChanges() method that the changes already existed before you
selected the row or you have code executing in an event handler that makes
changes to the underlying DataRow when navigating the data source.
Mind you the problem might lay in the DataSet being unable to determine if
the data has changed being its a byte array. If so do I need to supply a
special object to deal with the comparison.


No. The DataSet will correctly detect changes to a DataColumn of a DataRow
simply by setting the value. The DataSet is not concerned with the Type or
content of the value.

Here's a simple example of using a DataTable as a data source for a
DataGridView. I intend to show when and why the DataTable.GetCh anges()
method will return a non-null value. The sample will work with a DataSet
just as well.

Please realize that I have not attempted to build this code.

private DataTable table;

private void InitializeDataA ndBind()
{
table = new DataTable();
table.Columns.A dd(typeof(strin g), "Column1");
table.Rows.Add( "Row 1");
table.Rows.Add( "Row 2");

// commit changes to DataTable
table.AcceptCha nges();

DataTable changes = table.GetChange s();

// changes is null

// bind the DataTable to a DataGridView
dataGridView1.D ataSource = table;
}

/*
After the data is initialized and bound to the grid select a row in the
grid.
Then execute code to call table.GetChange s() by clicking a button on the
Form.
table.GetChange s will return null unless a DataRow was actually modified.
Using the DataBindings of a custom control will not change this behavior.
If your control modifies a DataRow
then GetChanges() will return a DataTable containing a clone of the modified
DataRow until
table.AcceptCha nges() is called. If your control does not modified the
DataRow to which it's bound then
table.GetChange s() will always return null until a DataRow is modified,
deleted or added.
*/

private void TestEdit()
{
// I assume table.GetChange s() returns null at this point for the
purpose of this demonstration
// Call this method before making changes to the DataTable.

// edit a row in code...

DataRow rowInEdit = table.Rows[0];

// call rowInEdit.Begin Edit() if you intend to keep the row in edit mode
until a later time
// in that case changes will not be commited to the row until
rowInEdit.EndEd it() is called.

// edit a row
rowInEdit["Column1"] = "Row 1 (edited)";

// now, table.GetChange s() will return a DataTable containing a clone of
rowInEdit since it was modified

// message will be displayed since the row was modified above
System.Diagnost ics.Debug.Write LineIf(rowInEdi t.RowState ==
DataRowState.Mo dified,
"DataRow is Modified");

// accept all changes to the table
table.AcceptCha nges();

DataTable changes = table.GetChange s();

// changes is null

// message will be displayed since all changes have been accepted.
System.Diagnost ics.Debug.Write LineIf(rowInEdi t.RowState ==
DataRowState.Un changed,
"Changes have been accepted. The DataRow is no longer
'Modified'.");
}

HTH
Jun 26 '06 #4
Hi John,
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?
Actually, your binding your control to the current DataRow of a DataTable,
"Table1", in a DataSet, but this question does clarify your problem.

To answer your question:

control.DataBin dings.Add("MsgD ata", this.dataSet1, "Table1.Dat a");

where MsgData is a property of control and this.dataSet1 contains a table
named, "Table1", which contains a DataColumn named, "Data".

In your example you have done the same thing using a different overload of
the Add method.
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.
My opinion as well.
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.


I created a test to see if the RichTextBox control behaved as you mentioned
but I did not see those results. I bound a DataColumn to the Text property
of a RichTextBox and navigated the DataSet using a DataGridView. It behaved
as expected without modifying the RowState of any DataRows. The
DataSet.GetChan ges() property always returns null until I change a DataRow
within the DataGrid.

When and how are you updating the title bar to display the number of
changes? Are you doing anything in that code block that might be changing a
DataRow? Do you have any code anywhere that is modifing any DataRow at any
time?

You must be making changes to a DataRow in code without even realizing it.
Simply binding a DataColumn to a RichTextBox, or any Control for that
matter, does not cause the state of a DataRow to be modified unless the
value of a DataColumn with a DataRow is explicitly changed in code or by the
user.

- Dave Sexton
Jun 26 '06 #5
Hi John,

I just had some time to look at the code you attached.

The DataGridView.Se lectionChanged 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.Se lectionChanged event handler
2. Place the following line of code at the end of the Form.Load event
handler:

((CurrencyManag er) this.BindingCon text[dataSet1, "Table1"]).ListChanged
+= new ListChangedEven tHandler(Form1_ ListChanged);

3. Create the following event handler for the ListChanged event of your data
source:

private void Form1_ListChang ed(object sender, ListChangedEven tArgs e)
{
this.DisplayCha ngeCount();
}

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@invalid.com > wrote in message
news:%2******** *******@TK2MSFT NGP03.phx.gbl.. .
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()
{
InitializeCompo nent();
this.userContro l11.DataBinding s.Add(new
System.Windows. Forms.Binding(" MsgData", this.dataSet1, "Table1.Dat a",
false));
}

/// Title bar does not change count
public Form1()
{
InitializeCompo nent();
/// this.userContro l11.DataBinding s.Add(new
System.Windows. Forms.Binding(" MsgData", this.dataSet1, "Table1.Dat a",
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

Jun 26 '06 #6
Hi Dave,

Thanks again, comments embedded.

"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:Og******** ******@TK2MSFTN GP04.phx.gbl...
Hi John,
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?
Actually, your binding your control to the current DataRow of a DataTable,
"Table1", in a DataSet, but this question does clarify your problem.

To answer your question:

control.DataBin dings.Add("MsgD ata", this.dataSet1, "Table1.Dat a");

where MsgData is a property of control and this.dataSet1 contains a table
named, "Table1", which contains a DataColumn named, "Data".

In your example you have done the same thing using a different overload of
the Add method.
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.


My opinion as well.
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.


I created a test to see if the RichTextBox control behaved as you
mentioned but I did not see those results. I bound a DataColumn to the
Text property of a RichTextBox and navigated the DataSet using a
DataGridView. It behaved as expected without modifying the RowState of
any DataRows. The DataSet.GetChan ges() property always returns null until
I change a DataRow within the DataGrid.


The RichTexBox works as I expect. Unless you edit the data in the
RichTextBox the row does not change. If you edit the data in the
RichTextBox the row updates.

Test:
comment out the binding for MsgData.
Run the application
Select each row, arrow up and down, whatever
(Note the changed records: 0 --- always)
Change the text in the RichTextBox
Leave the row you are currently on
(Note the changed records: 1 --- As expected)

This is what I want my control to do, HOW?

Add the binding for MsgData mucks the whole thing up. Every time you
change rows the change records incerments until the all the records have
been changed.

When and how are you updating the title bar to display the number of
changes? Are you doing anything in that code block that might be changing
a DataRow? Do you have any code anywhere that is modifing any DataRow at
any time?
The title bar is updated via dataGridView1_S electionChanged . The code gets
the changes, writes the count and returns. Nothing else. The same code is
run if the MsgData is bound or not.

You must be making changes to a DataRow in code without even realizing it.
Simply binding a DataColumn to a RichTextBox, or any Control for that
matter, does not cause the state of a DataRow to be modified unless the
value of a DataColumn with a DataRow is explicitly changed in code or by
the user.
I don't see where the MsgData in control can be modified. there is only the
get / set accessors. The paint function only shows the number of bytes so
I know the row has updated.

- Dave Sexton

Jun 26 '06 #7
Dave,

This does not change anything. My main project does not even have the code
to update the title bar, it only looks for changes when the user presses
update and/or when the form is closed. The main project get the change and
passes them to a SQL data adaptor which then does its thing.

The problem is my control and not the form or the DataSet. I need to
modify the way the control was created or the way it is bound to the data.
I am at a loss for which.

Regards,
John

"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:OV******** ******@TK2MSFTN GP04.phx.gbl...
Hi John,

I just had some time to look at the code you attached.

The DataGridView.Se lectionChanged 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.Se lectionChanged event handler
2. Place the following line of code at the end of the Form.Load event
handler:

((CurrencyManag er) this.BindingCon text[dataSet1, "Table1"]).ListChanged
+= new ListChangedEven tHandler(Form1_ ListChanged);

3. Create the following event handler for the ListChanged event of your
data source:

private void Form1_ListChang ed(object sender, ListChangedEven tArgs e)
{
this.DisplayCha ngeCount();
}

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@invalid.com > wrote in message
news:%2******** *******@TK2MSFT NGP03.phx.gbl.. .
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()
{
InitializeCompo nent();
this.userContro l11.DataBinding s.Add(new
System.Windows. Forms.Binding(" MsgData", this.dataSet1, "Table1.Dat a",
false));
}

/// Title bar does not change count
public Form1()
{
InitializeCompo nent();
/// this.userContro l11.DataBinding s.Add(new
System.Windows. Forms.Binding(" MsgData", this.dataSet1, "Table1.Dat a",
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


Jun 26 '06 #8
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, INotifyProperty Changed

Regards,
John

"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:OV******** ******@TK2MSFTN GP04.phx.gbl...
Hi John,

I just had some time to look at the code you attached.

The DataGridView.Se lectionChanged 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.Se lectionChanged event handler
2. Place the following line of code at the end of the Form.Load event
handler:

((CurrencyManag er) this.BindingCon text[dataSet1, "Table1"]).ListChanged
+= new ListChangedEven tHandler(Form1_ ListChanged);

3. Create the following event handler for the ListChanged event of your
data source:

private void Form1_ListChang ed(object sender, ListChangedEven tArgs e)
{
this.DisplayCha ngeCount();
}

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@invalid.com > wrote in message
news:%2******** *******@TK2MSFT NGP03.phx.gbl.. .
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()
{
InitializeCompo nent();
this.userContro l11.DataBinding s.Add(new
System.Windows. Forms.Binding(" MsgData", this.dataSet1, "Table1.Dat a",
false));
}

/// Title bar does not change count
public Form1()
{
InitializeCompo nent();
/// this.userContro l11.DataBinding s.Add(new
System.Windows. Forms.Binding(" MsgData", this.dataSet1, "Table1.Dat a",
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


Jun 26 '06 #9
Thanks for the help,

In fact that works perfectly now.

Regards,
John
Jun 26 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1717
by: Colin Robinson | last post by:
Help please I have an example class called Person with 2 public properties Firstname and Lastname, I cant create a textbox on an asp.net form bound to the Person.Firstname property Can anyone help with the required syntax? if i do TExtbox1.text = x.firstname it works ok, but I want to edit the textbox setting the value of x.firstname.
3
3155
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method, depending on which menu item a user selects. Each of these controls follows the same basic pattern: Get a dataset from the database and then display the results using basic databinding. Everything works fine except that I'll occaisionally get an...
6
3570
by: John Bailey | last post by:
I have a web page with a formview, and a multiview in the formview. When I databind the values inside the multiview views, there is no option for two-way databinding. The form populates fine, but when it calls the update method, it calls it with no parameters. Is there just no support for two-way databinding inside these controls, or is there a technique I am missing?
0
1298
by: Simon Gregory | last post by:
I am currently attempting to figure out how the new databinding stucture works in ASP.NET 2.0 after working with v1.0 & v1.1 for several years. It seems that if you wish to do set up databinding at Design Time, you are restricted to using one of the 5 xxxDataSource controls. The data in our websites are usually obtained via a set of webservices and are contained in a set of strongly typed relational DataSets.
8
2181
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got answered... In 1.1 we always did our own myDataAdapter.fills and we liked that control for lots of good reasons. Now the new DataSource (or is it a TableAdapter:Dataset) automatically fills the Gridview. How can we control that fill? In a...
2
4264
by: John R. Lewis | last post by:
I posted this yesterday with a different email address. I am reposting with my fake-address as given to me by Microsoft so that I can be guraranteed a response from a support representative. Sorry for the repost. I'd like to make use of the asp:Wizard control to present a step-by-step guided experience for my user to fill out a complicated data-entry form. I'd like to make use of two-way databinding provided by the asp:FormView control...
1
16261
by: Owen Blacker | last post by:
I've spent loads of time Googling to try to work this one out and I'm sure it's something obvious. I get an InvalidOperationException reading "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control" when I start my page. Unless I'm missing something obvious, this is *not* the same issue as the "2-way databinding cascading lists" issue in...
1
2424
by: esakal | last post by:
Hello, I have a very strange problem which involve databinding in winform c#.net 2 . I have a user control which holds textbox inside. the user control has property which reflect the inner textbox text
7
1729
by: rodchar | last post by:
hey all, for simplicity's sake i have a single textbox inside a user control. once i drag that user control onto my page is there a way to attach a binding expression to it at runtime? thanks, rodchar
0
1898
by: Dave A | last post by:
I have a user control that is dynamically loaded into a repeater; (so the user control appears several times) The user control features a text box and a delete button. When the delete button is clicked the usercontrol raises an event indicating that the data in the database that relates to this user control is to be deleted.
0
8975
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8801
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9516
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9286
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9219
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6774
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4840
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2200
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.