Hi TT!
I have tried using SuspendLayou as you sugested. In my derived class I have
new DataSource and DataMember properties (look at the pasted code).
Unfortunatelly this does not help. Am I doing something wrong?
I told you earlier that the repainting doesn't seem to work when I edited
the cells in the first view. This is actually not the case. From what I can
see the problem occurs when I have selected a cell so that is is marked (just
click in a cell in a datagrid and the text is highlited). When I am in this
state and changes the data source (or datamember since I just shift between
tables in the dataset), then that specific row with the selected cell is not
repainted correctly in the new view.
----------------------------------------------------------
// DataSource and DataMember property
public new object DataSource
{
get { return base.DataSource; }
set
{
this.SuspendLayout();
if (this.AutoSave) SaveChanges();
if (value.GetType().GetInterface("Offertering.Data.IDataList") != null)
{
base.DataSource = ((Offertering.Data.IDataList)value).DataSource;
((DataSet)this.DataSource).AcceptChanges();
}
else if (value.GetType() == typeof(DataSet))
{
base.DataSource = value;
((DataSet)this.DataSource).AcceptChanges();
}
// New property
AllowNewRow = AllowNewRow;
this.ResumeLayout(false);
}
}
public new string DataMember
{
get { return base.DataMember; }
set
{
BindingManagerBase bm = null;
this.SuspendLayout();
if (this.AutoSave) SaveChanges();
base.DataMember = value;
// If DataSource is a DataSet, then implement AllowRow for the datamember
if (this.DataSource != null && this.DataSource.GetType() ==
typeof(DataSet))
{
// Implement the AllowNewRow setting for the new DataMember object
AllowNewRow = AllowNewRow;
}
}
}
--
/ ScubaD
TT (Tom Tempelaere) said:
Hi ScubaD,
ScubaD said:
Hi!
I derived a new class from a DataGrid control and added some functionality
to it. Among other things a method that autosizes the columns displayed.
When I change the data source and data member of the datagrid after having
updated some data in it, it sometimes does not display correctly. What
happens is that some cells from the old view is visible in the new view. I do
not know what is the problem, but my guess is that it has something to do
with the repainting of the derived datagrid.
Do I need to do something in the derived data grid to get the painting to
work correctly?
Before you change the data source, call "SuspendLayout" on the DataGrid and
call ResumeLayout after making the changes. I believe that may solve your
issue.
If that doesn't work try the following:
BindingManagerBase bm = yourDataGrid.BindingContext [
yourDataGrid.DataSource,
yourDataGrid.DataMember
];
bm.SuspendBinding( );
// <-- modify the data source here
bm.ResumeBinding( );
Hope this helps,