Can anyone write me a code where I can create a hierarchical grid programmatically by adding each row separately? I know data binding is a nice cute feature but our software design doesn't permit us using the binding directly. So I need to add data one by one in the grid, that too in hierarchical fashion.
The concept of bands is kinda confusing.
Can anyone please just write a small like of code where I create a grid, add couple of columns and a couple of rows to it. And for each row I need to two columns and 1 row each.
Thanks. I just need an idea of the thing.
You can create a DataSet with related tables, then fill it with your data. Then set your grid's DataSource to the DataSet and DataBind it. Everything will then fall into place.
Think of bands as related tables. If you are doing an invoicing system, you might have your customer list in band 0, your order list in band 1, and your order detail list in band 2. Once you bind such a dataset to a grid, the orders will be displayed under their respective customer, etc.
I posted an example here: http://forums.infragistics.com/forums/p/3298/17902.aspx#17902
Hmm. Thanx a lot. I find no issues with the above apart from the extra over head of creating a data set row by row and then binding it rather than simply adding the rows directly.
Though through trail and error I have been able to create it. Following is the code for that (firstEverGrid is a grid already declared at design time)
UltraGridBand firstBand = new UltraGridBand(true);
firstBand.Columns.Add("column2", "doosra column");
secondBand.Columns.Add("column3", "teesra column");
firstEverGrid.Bands.Add(firstBand);
UltraGridCell cell3 = new UltraGridCell("hello baby3");
UltraGridCell cell5 = new UltraGridCell("hello baby5");
UltraGridCell cell7 = new UltraGridCell("hello baby7");
Row1.Cells.Add(cell1);
Row1.Cells.Add(cell2);
Row2.Cells.Add(cell3);
Row2.Cells.Add(cell4);
Row3.Cells.Add(cell5);
Row3.Cells.Add(cell6);
Row4.Cells.Add(cell7);
Row4.Cells.Add(cell8);
Row1.Rows.Add(Row3);
Row2.Rows.Add(Row4);
firstEverGrid.Rows.Add(Row1);
firstEverGrid.Rows.Add(Row2);
----
This create twos rows each containing one row inside.
Now can anyone tell me how to add another column in each row containing a simple checkbox ?
Thanx
Good morning Edward,
I overlooked and missed the link you provided. Thank you for the nice working code you posted! I added a few more lines just to help someone new like I am.
Reference to Edward McCarroll's original post
Public Function CreateDataset() As DataSet Dim lResult As New DataSet("myDataset") Dim getLevel1QStr As String = "SELECT InvoiceNo, Description FROM Level1" Dim getLevel2QStr As String = "SELECT InvoiceNo, PartNo, Description FROM Level2" Dim getLevel3QStr As String = "SELECT PartNo, SerialNo, Description FROM Level3"
Dim level1Table As New DataTable("Level1") lResult.Tables.Add(level1Table) lResult.Tables("Level1").Load(GetDataReader(getLevel1QStr))
Dim level2Table As New DataTable("Level2") lResult.Tables.Add(level2Table) lResult.Tables("Level2").Load(GetDataReader(getLevel2QStr))
lResult.Relations.Add(lResult.Tables("Level1").Columns("InvoiceNo"), lResult.Tables("Level2").Columns("InvoiceNo"))
Dim level3Table As New DataTable("Level3") lResult.Tables.Add(level3Table) lResult.Tables("Level3").Load(GetDataReader(getLevel3QStr))
lResult.Relations.Add(lResult.Tables("Level2").Columns("PartNo"), lResult.Tables("Level3").Columns("PartNo"))
Return lResultEnd Function
Public Function GetDataReader(ByVal queryString As String) As SqlDataReader
'AppConnectionString = connection string Dim myConnection As New SqlConnection(AppConnectionString) Dim myCommand As New SqlCommand(queryString, myConnection) 'Set the command myCommand.CommandType = CommandType.Text 'Execute the command myConnection.Open() Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Return SqlDataReader Return result
End Function
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack = True Then Me.UG1.DataSource = CreateDataset() 'Create and return a dataset Me.UG1.DataBind() 'Bind to Grid Me.UG1.DisplayLayout.ActiveRow = Me.UG1.Rows(0) 'Set pointer to first row End If
End Sub 'Page_Load
Thanks,Thai Nguyen
Hi ,
I m also suffering from same problem ....can you help me. I have code snippest which is bind DataSet .
DataSet dsSearch = new DataSet();
{
new DataColumn[ { dsSearch.Tables["Table1"].Columns[0], dsSearch.Tables["Table1"].Columns[2] }, false);
new DataColumn[ { dsSearch.Tables["Table2"].Columns[7] }, false);
}
this.UG1.DataSource = dsSearch;
Problem is ....It is not display third level data. Its only display 2 level data.
I want to display
1.Comapnay
2.Contact Name 3.Matter Name
2.Contact Name
3.Matter Name
Is it possible with Hierarchical grid.
If I'm correctly reading the code where you're creating your DataRelation objects, you have three tables: Table, Table1, and Table2. The relations you're creating mean that Table1 is a child of Table, and Table2 is also a child of Table.
WebGrid isn't capable of showing multiple sets of child tables in this fashion. You can only have one child band (roughly analagous to a single DataTable) for any one parent band.
Hi MacDonald
Thank you for ur support....can we have any other control thru wich i achive this functionality.
anup84,
I don't myself know of a certain way to accomplish this result using our ASP.NET controls.
As a thought, you might be able to handle this using our new WebDataTree control, using a table row in the template of each node. Doing so is beyond my own personal knowledge; if you want to investigate this and find you need assistance, I suggest you post in the WebDataTree forum.