J
John J. Hughes II
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
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