How do you create a drop-down hierarchical Data Grid?

A

Anonieko Ramos

Is there a way to dynamically create a drop-down hierarchical data
grid?
You may want to look at this reference. It has a 1-level hierarchy.

http://searchvb.techtarget.com/vsnetTip/1,293823,sid8_gci833650,00.html



If you have a master detail tables, you can retrieve them and set the
DataRelation on the fly like this:

Orders table Logs table
+------------+ +------------+
| ORDER_ID |---------------| ORDER_ID |
| | | |
+------------+ +------------+



// ....

try
{
// Open connection.
conn.Open();

// The ds has (two) 2 result sets.
dsOrdersList = SqlHelper.ExecuteDataset(conn, ... );

// Close connection.
if (conn != null && conn.State != ConnectionState.Closed)
conn.Close();

// Name the 2 DataTables as 'Orders', 'Logs'
dsOrdersList.Tables[0].TableName = "Orders";
dsOrdersList.Tables[1].TableName = "Logs";

//-----------------------------------------------------
// important so that the HIERARCHICAL view will work!
// we define a data relation in the dataset, "Orders_logs"
//-----------------------------------------------------

dsOrdersList.Relations.Add("Orders_Logs",
dsOrdersList.Tables["Orders"].Columns["order_id"],
dsOrdersList.Tables["Logs"].Columns["order_id"]);

// Create the dataview which will become the data source.
DataView dv = dsOrdersList.Tables["Orders"].DefaultView;
dv.Sort = sortExpression;

// Bind it to data grid.
dgrdOrdersList.DataSource = dv;
}
catch
{ // Something went wrong in getting the data set!!!!
// Close connection.
if (conn != null && conn.State != ConnectionState.Closed)
conn.Close();

throw;
}

return ( dsOrdersList );
}
// .....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top