We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Leave nodes in hierarchical databound grid

Hello, I want to use a databound grid to navigate a hierarchical tree. When I know that I am on a leave node (current record has no child records), I want to display an 'empty' bitmap in the GridDataBoundRowExpandCell control in stead of a '+' or '-' bitmap. Any idea's? Herman

2 Replies

AD Administrator Syncfusion Team March 23, 2003 06:52 PM UTC

There may be a better way to handle this. but here is one way. You can use the DrawCellEvent, and draw this cell yourself. In your code, you would need to check for any childrows for the node, and draw the cell if there are none. One technical problem is that the childrows are not known until the node is expanded. To handle this, you can do a 'blind' expand using BeginUpdate/EndUpdate. Here is a try at this.
private void gridDataBoundGrid1_DrawCell(object sender, GridDrawCellEventArgs e)
{
	if( e.ColIndex == 1)
	{
		GridBoundRecordState state = this.gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(e.RowIndex);
		if( state.HasChildList && state.ChildCount == 0)
		{
			int count;
			if (state.Position >= state.Table.Count)
			{
				count = 0; //addnew row
			}
			else
			{
				this.gridDataBoundGrid1.BeginUpdate();
				this.gridDataBoundGrid1.Model.SuspendChangeEvents();
				this.gridDataBoundGrid1.ExpandAtRowIndex(e.RowIndex);
				count = state.ChildCount ;
				this.gridDataBoundGrid1.CollapseAtRowIndex(e.RowIndex);
				this.gridDataBoundGrid1.Model.ResumeChangeEvents();
				this.gridDataBoundGrid1.EndUpdate();
			}
			if(count == 0)
			{
				using(SolidBrush brush = new SolidBrush(e.Style.BackColor))
				{
					e.Graphics.FillRectangle(brush, e.Bounds);
					e.Cancel = true;
				}
			}
		}
	}
}


HM Herman Muys March 24, 2003 09:34 AM UTC

Why I couln't find this myself? Thanks, Herman

Loader.
Live Chat Icon For mobile
Up arrow icon