Exactly,
What you can do is
1> store the position of the vertical scroll bar.
2> Add row
3> Restore the original position of the vertical scroll bar.

Regards
Vinod

-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Sandhya S
Sent: Tuesday, December 21, 2004 12:06 PM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: [ADVANCED-DOTNET] Flickering of Datagrid.

Hi,
   I have a custom data grid control which inherits from the data grid.
The problem I am facing here is that the vertical scroll bar scrolls to the
top (first row) each time a new row is added to the grid. But then I want
the scroll bar to stay where it was before adding the row and should move
only when the scroll bar is used by the user. The vertical scroll bar is
visible once the no. of rows goes beyond the height of the grid. but then
this is done automatically by the datagrid. There is no specific method
written to scroll. Every time a row is added the paint method is invoked in
which the base paint method of the grid paints from the first to the last
row of the grid. Will this make the scroll bar to point to the first row ??
If so how can this be stopped ?

Some more to add on Datagrid.
The paint method of the datagrid is overidden in which the base paint method
is invoked. Along with this a progress bar is also painted for one of the
columns. But then there is too much of flicker while adding new rows. As the
rows increase the flicker is more visible. The flicker was observed even
without the paiting of the progress bar. That is even if we comment the
paint method itself and allow the grid to take care of painting there is a
lot of flicker. Can this flicker be stopped or reduced.

This was developed on .Net Framework 1.1 Version 1.1.4322 with service pack
SP1 installed.

The overriden paint method :
                protected override void OnPaint(PaintEventArgs pe)
                {

                        // If grid is disabled don't paint progress bar
                        if(!this.Enabled)
                                return;

                        // If grid is not associated with any Data Source,
then don't paint progress bar
                        DataView dv = (DataView)this.DataSource;
                        if(dv == null)
                                return;

                        // Copy the contents of DataView assoicated with
grid to a DataTable
                        System.Data.DataTable oTable = CreateTable(dv);
                        //Perform base painting
                        base.OnPaint(pe);

                        try
                        {
                                // If no table, do nothing
                                if(oTable == null)
                                        return;
                                int nRow = 0;
                                // For all the rows that are there in Grid
call PaintProgressCell function
                                int nCol = 4; // Index of column to be
panited
                                //int nColumn = 7;
                                DataGrid.HitTestInfo hti = null;
                                foreach(DataRow oRow in oTable.Rows)
                                {
                                        if(oRow == null)
                                                continue;
                                        //get the cell bounds of the row and
progress column.
                                        Rectangle rect1 =
this.GetCellBounds(nRow, nCol);
                                        //Get the point of the rectangle for
that row and column.
                                        Point p1 = new Point(rect1.X,
rect1.Y);
                                        //get the hit test info of the point
where grid is clicked.
                                        //In this situation the row and
progress col to be painted.
                                        hti = this.HitTest(p1);
                                        //if the type of the row & column to
be painted is a cell then go ahead.
                                        if (hti.Type ==
DataGrid.HitTestType.Cell)
                                        {
                                                //if it is the progress
column to be painted then go ahead and paint the progress bar.
                                                if(nCol == hti.Column)

PaintProgressCell(pe.Graphics, oRow, nRow, nCol);
                                        }
                                        nRow ++;
                                }
                        }
                        catch(Exception e)
                        {
                                e.ToString();
                        }
                }


Thanks & Regards
Sandhya




This message is free from Virus - IMSS

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com Some .NET
courses you may be interested in:

Essential .NET: building applications and components with C# November 29 -
December 3, in Los Angeles http://www.develop.com/courses/edotnet

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
Some .NET courses you may be interested in:

Essential .NET: building applications and components with C#
November 29 - December 3, in Los Angeles
http://www.develop.com/courses/edotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to