datagrid event

  • Thread starter Thread starter 11Oppidan
  • Start date Start date
1

11Oppidan

I have a parent and child datatable which i am viewing in a datagrid. does
anyone know the event that is fired when the user expands the node to look
at the child table?

thanks.
 
Hi 11Oppidan,

Thanks for your post.

Winform DataGrid has no build-in event for this operation. Actually,
DataGrid internally calculates the "+" rectangle itself in MouseDown event,
then determine if the mouse position falls into this rectangle. That is:
DataGrid do the hittest internally without expose outside.

In details, for relation table databinding, DataGrid will call
DataGridRelationshipRow.OnMouseDown for the hittest operation. If you use
Reflector to view DataGridRelationshipRow.OnMouseDown method, you will see
that it internally calls this.PointOverPlusMinusGlyph(x, y, rowHeaders,
alignToRight)) to determine if the mouse falls in the "+" node rectangle.
It does the hittest like this:
private bool PointOverPlusMinusGlyph(int x, int y, Rectangle rowHeaders,
bool alignToRight)
{
if (((this.dgTable == null) || (this.dgTable.DataGrid == null)) ||
!this.dgTable.DataGrid.AllowNavigation)
{
return false;
}
Rectangle rectangle1 = rowHeaders;
if (!base.DataGrid.FlatMode)
{
rectangle1.Inflate(-1, -1);
}
Rectangle rectangle2 = this.GetOutlineRect(rectangle1.Right - 14, 0);
rectangle2.X = this.MirrorRectangle(rectangle2.X, rectangle2.Width,
rectangle1, alignToRight);
return rectangle2.Contains(x, y);
}

Maybe we can do the calculation ourselves. However, the key point is how to
get rowHeaders rectangle position and size ourselves. The rowHeaders is a
private field of DataGrid, which there is not easy way for us to access.
DataGrid uses ComputeLayout() to calculate the rowHeaders rectangle's
position and size. Here is the full code:
//You can get this from Reflector
private void ComputeLayout()
{
bool flag1 = !this.isRightToLeft();
Rectangle rectangle1 = this.layout.ResizeBoxRect;
this.EndEdit();
this.ClearRegionCache();
DataGrid.LayoutData data1 = new DataGrid.LayoutData(this.layout);
data1.Inside = base.ClientRectangle;
Rectangle rectangle2 = data1.Inside;
int num1 = this.BorderWidth;
rectangle2.Inflate(-num1, -num1);
Rectangle rectangle3 = rectangle2;
if (this.layout.CaptionVisible)
{
int num2 = this.captionFontHeight + 6;
Rectangle rectangle4 = data1.Caption;
rectangle4 = rectangle3;
rectangle4.Height = num2;
rectangle3.Y += num2;
rectangle3.Height -= num2;
data1.Caption = rectangle4;
}
else
{
data1.Caption = Rectangle.Empty;
}
if (this.layout.ParentRowsVisible)
{
Rectangle rectangle5 = data1.ParentRows;
int num3 = this.parentRows.Height;
rectangle5 = rectangle3;
rectangle5.Height = num3;
rectangle3.Y += num3;
rectangle3.Height -= num3;
data1.ParentRows = rectangle5;
}
else
{
data1.ParentRows = Rectangle.Empty;
}
int num4 = this.headerFontHeight + 6;
if (this.layout.ColumnHeadersVisible)
{
Rectangle rectangle6 = data1.ColumnHeaders;
rectangle6 = rectangle3;
rectangle6.Height = num4;
rectangle3.Y += num4;
rectangle3.Height -= num4;
data1.ColumnHeaders = rectangle6;
}
else
{
data1.ColumnHeaders = Rectangle.Empty;
}
bool flag2 = this.myGridTable.IsDefault ? this.RowHeadersVisible :
this.myGridTable.RowHeadersVisible;
int num5 = this.myGridTable.IsDefault ? this.RowHeaderWidth :
this.myGridTable.RowHeaderWidth;
data1.RowHeadersVisible = flag2;
if ((this.myGridTable != null) && flag2)
{
Rectangle rectangle7 = data1.RowHeaders;
if (flag1)
{
rectangle7 = rectangle3;
rectangle7.Width = num5;
rectangle3.X += num5;
rectangle3.Width -= num5;
}
else
{
rectangle7 = rectangle3;
rectangle7.Width = num5;
rectangle7.X = rectangle3.Right - num5;
rectangle3.Width -= num5;
}
data1.RowHeaders = rectangle7;
if (this.layout.ColumnHeadersVisible)
{
Rectangle rectangle8 = data1.TopLeftHeader;
Rectangle rectangle9 = data1.ColumnHeaders;
if (flag1)
{
rectangle8 = rectangle9;
rectangle8.Width = num5;
rectangle9.Width -= num5;
rectangle9.X += num5;
}
else
{
rectangle8 = rectangle9;
rectangle8.Width = num5;
rectangle8.X = rectangle9.Right - num5;
rectangle9.Width -= num5;
}
data1.TopLeftHeader = rectangle8;
data1.ColumnHeaders = rectangle9;
}
else
{
data1.TopLeftHeader = Rectangle.Empty;
}
}
else
{
data1.RowHeaders = Rectangle.Empty;
data1.TopLeftHeader = Rectangle.Empty;
}
data1.Data = rectangle3;
data1.Inside = rectangle2;
this.layout = data1;
this.LayoutScrollBars();
if (!rectangle1.Equals(this.layout.ResizeBoxRect) &&
!this.layout.ResizeBoxRect.IsEmpty)
{
base.Invalidate(this.layout.ResizeBoxRect);
}
this.layout.dirty = false;
}
If you really want to get the rowheaders rectangle, we have to simulate the
same calculation algorithm like the ComputeLayout() does. Hope this
information helps.

Additionally, if you only want to get the notification, when the user press
the link to navigate to the child table, we can use Navigate event to get
this done.
======================================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
11Oppidan said:
I have a parent and child datatable which i am viewing in a datagrid. does
anyone know the event that is fired when the user expands the node to look
at the child table?

thanks.

DataGrid.Navigate is fired when they actually go to the child table, or
return to the parent table, if that is what you need. It does not fire
when the parent table [+] is expanded though.
 
Many thanks for your advice.


Lee Gillie said:
11Oppidan said:
I have a parent and child datatable which i am viewing in a datagrid.
does anyone know the event that is fired when the user expands the node
to look at the child table?

thanks.

DataGrid.Navigate is fired when they actually go to the child table, or
return to the parent table, if that is what you need. It does not fire
when the parent table [+] is expanded though.
 
Back
Top