Skip to main content

Grid node index no.

Comments

4 comments

  • Dapfor Team

    Hi,

    Here is a code, demonstrating how to get a parent row when the user clicks on a child header:

     

    grid.MouseClick += delegate(object sender, MouseEventArgs e)
    {
        //Test the case when the user clicks on the child header
        Header header = grid.HitTests.HeaderTest(e.Location);
        if(header != null && header.Level > 0)
        {
            Row parentRow = null;

            //Get child header bounds
            Rectangle headerBounds = grid.HitTests.HeaderVisibleBoundsTest(e.Location);
            if(headerBounds.Height > 0 && headerBounds.Width > 0)
            {
                //Get the first visible row below the header
                Row row = grid.HitTests.RowTest(new Point(e.Location.X, headerBounds.Bottom));
                
                //if the row is found - get its parent.
                parentRow = row != null ? row.Parent : null;
            }

            if (parentRow != null)
            {
                //Do something
            }
        }
    };

     

    Best regards,

    Dapfor

    0
  • Jenny Tan

    thx...

     

    How to change the child header's back color to gray when the user clicks on a child header?

     

    Regards,

    Jenny

    0
  • Dapfor Team

    Hi,

    To do it, invalidate the child header in the MouseDown event handler: header.Invalidate()

    Then add the following code:

    grid.PaintColumnCaption += delegate(object sender, PaintColumnCaptionEventArgs e)

    {

        Point location = grid.PointToClient(Cursor.Position);

        Column column = grid.HitTests.ColumnTest(location);    

        if (column == e.Column && (MouseButtons & MouseButtons.Left) == MouseButtons.Left)    

        {

            e.Appearance.BackColor = Color.Gray;

        }

    };

     

    Best regards,

     Dapfor

    0
  • Jenny Tan

    thanks a lot...

     

    Can i ask when the user clicks on the child header, then click a delete row button, how to get the parent row to delete the whole row in button click event?

     

    Regards,

    Jenny Tan

    0

Please sign in to leave a comment.

Powered by Zendesk