RE: Derived DataGrid not displeyed correctly by ScubaD
ScubaD
Tue Dec 20 00:28:03 CST 2005
Hi TT,
I actually found what was wrong. The problem was that I used
'SuspendLayout()' on a higher level so I actually made two nested calls to
the function. This caused the DataGrid not to display correctly. Anyway,
thankyou for your help, it was good for me anyway because it got me thinking
a bit..
Just for curiosity, why shouldn't I derive from datagrid? Do you have bad
experiences of this or is it just not 'common practise'?
Thanks,
/ Daniel
--
/ ScubaD
"TT (Tom Tempelaere)" wrote:
> Hi ScubaD,
>
> "// ScubaD" wrote:
>
> > 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
>
> Sorry for the late response, but have your tried the second suggestion I
> posted (ie using SuspendBinding & ResumeBinding on the binding manager?
>
> On a sidenote, AVOID *new* methods! Do not overwrite, *ever*, unless
> something forces you and you have no other way of accomplishing this.
>
> Second, don't derive from DataGrid if it isn't necessary. Instead make a
> custom control (System.Windows.Forms.UserControl) and drag a DataGrid onto
> it. Of course this could be clumsy if you intend to "enhance" the DataGrid
> with new functionality so that it is still a generic UI component.
>
> I would definitely go for my advice n°2. It that doesn't work still, force a
> repaint for the complete control (ie call Control.Invalidate method on the
> DataGrid)
>
> Hope this helps, and kind regards,
> --
> Tom Tempelaere.
>