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 );
}
// .....
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 );
}
// .....