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

Populate a GridGroupingControl from text values

Hi. I have a GridGroupingControl which I would like to populate. I am receiving log messages via .NET remoting and have the values in string format. What is the simplest way that I can take these log messages and display them in a GridGroupingControl? I have the fields: ID, Message, Service, Date, Level. I receive a new log object with these values every few seconds. Thanks, David

3 Replies

AD Administrator Syncfusion Team March 5, 2004 05:42 PM

You should create a DataTable object and set it as datasource for the control. When you add new records to the table the new rows will automatically show up in the grid. Here is some code that shows how to create and add a records to a DataTable. private void InitializeDataTable() { int recordCount = 100; Random random = new Random(DateTime.Now.Millisecond); string[] states = new string[]{"North Carolina", "South Carolina", "Washington", "Nevada", "Ohio"}; int numStates = states.GetLength(0); string nameFormat = "Name{0}"; this.table = new DataTable("Test"); DataColumn col = table.Columns.Add(); col.DataType = typeof(string); col.ColumnName = "Name"; col = table.Columns.Add(); col.DataType = typeof(string); col.ColumnName = "State"; col = table.Columns.Add(); col.DataType = typeof(int); col.ColumnName = "Zip"; for(int i = 0; i < recordCount; i++) { DataRow row = this.table.NewRow(); row["Name"] = string.Format(nameFormat, i); row["State"] = states[random.Next(numStates-1)]; row["Zip"] = random.Next(9999); this.table.Rows.Add(row); } } Stefan Hoenig


DA David March 7, 2004 12:39 PM

This is perfect! Thanks. One more quick question though. Using the DataTable as you''ve described, how do I tell the GridGroupingControl to stretch the grid to fill the entire width of the control? I''ve docked it as "Fill" and it''s anchored to the upper left. Is there a property I should set that does automatic stretching and column resizing? Thanks!


AD Administrator Syncfusion Team March 8, 2004 03:50 AM

Currently, there is no property to handle this. But you can catch an event and do the sizing tere to fill up the client area. Here are some snippets that make the right-most column fill the client area. //in formload this.gridGroupingControl1.TableControl.Model.QueryColWidth += new GridRowColSizeEventHandler(grid_QueryColWidth); this.SCROLLBARWIDTH = SystemInformation.VerticalScrollBarWidth; this.lastCol = myDataTable.Columns.Count + 1;
//the handler
private void grid_QueryColWidth(object sender, GridRowColSizeEventArgs e)
{
	if(e.Index == this.lastCol)
	{
		int vscrollwidth = ((this.gridGroupingControl1.TableControl.Model.RowHeights.GetTotal(0, this.gridGroupingControl1.TableControl.Model.RowCount)  
					+  this.gridGroupingControl1.TableOptions.CaptionRowHeight)
					> this.gridGroupingControl1.ClientSize.Height) 
				? SCROLLBARWIDTH :0;
		e.Size = this.gridGroupingControl1.ClientSize.Width - 
				this.gridGroupingControl1.TableControl.Model.ColWidths.GetTotal(0, e.Index - 1)
				- vscrollwidth;
		e.Handled = true;
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon