Re: Databinding to user control
- From: "John J. Hughes II" <no@xxxxxxxxxxx>
- Date: Mon, 26 Jun 2006 07:50:44 -0400
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.GetChanges() 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:uB6TzCKmGHA.4052@xxxxxxxxxxxxxxxxxxxxxxx
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.AcceptChanges() 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@xxxxxxxxxxx> wrote in message
news:eHxOOIJmGHA.4864@xxxxxxxxxxxxxxxxxxxxxxx
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 RichTextControls 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 OnPropertyChanged and I have tried OnValidation.
//
// ctrlMsgEditor1
//
this.ctrlMsgEditor1.Cursor = System.Windows.Forms.Cursors.Default;
this.ctrlMsgEditor1.DataBindings.Add(new
System.Windows.Forms.Binding("MsgData", this.dsMsg1, "Messages.Data",
true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
this.ctrlMsgEditor1.Dock = System.Windows.Forms.DockStyle.Right;
this.ctrlMsgEditor1.Location = new System.Drawing.Point(306, 0);
this.ctrlMsgEditor1.MsgData = null;
this.ctrlMsgEditor1.Name = "ctrlMsgEditor1";
this.ctrlMsgEditor1.Size = new System.Drawing.Size(347, 328);
this.ctrlMsgEditor1.TabIndex = 7;
//// The custom user control
[System.ComponentModel.DefaultBindingProperty("MsgData")]
public partial class ctrlMsgEditor : UserControl
{
private byte[] _MsgData = new byte[1];
[System.ComponentModel.Bindable(true), Browsable(true),
Category("Data"), Description("Encoded data to be displayed")]
public byte[] MsgData
{
get
{
lock (this)
{
return _MsgData;
}
}
set
{
lock (this)
{
this._MsgData = value;
this.DisplayData(this._MsgData);
}
}
}
public ctrlMsgEditor()
{
InitializeComponent();
}
private void DisplayData(byte[] msgData)
{
/// Display the data
}
}
Regards,
John
.
- Follow-Ups:
- Re: Databinding to user control
- From: Dave Sexton
- Re: Databinding to user control
- References:
- Databinding to user control
- From: John J. Hughes II
- Re: Databinding to user control
- From: Dave Sexton
- Databinding to user control
- Prev by Date: Re: dataadapter.fill slow
- Next by Date: Re: Question regarding timer.
- Previous by thread: Re: Databinding to user control
- Next by thread: Re: Databinding to user control
- Index(es):
Relevant Pages
|
Loading