Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
140
How to implement a multi-level grid in WebHirachicalDataGrid
posted

Hi,

Actually i want to Create a webHirachicalDataGrid and for First Child it is working Fine but i want to Create Parent-> Child -> GrandChild,i am Creating a relation same like as i have Created in the Parent-. Child but the Relation between Child -> GrandChild is not Building up. My Code is here :

private DataSet CreateDataSource()
{
DataSet ds = new DataSet();
ds.Tables.Add(CreateGridDataSourceForModules("Module"));
ds.Tables.Add(CreateGridDataSourceForSubModules("TRN_CODE", true));
ds.Tables.Add(CreateTrnOperations("TRN_OPERATIONS", true));

DataRelation dr = new DataRelation("id", ds.Tables["Module"].Columns["id"], ds.Tables["TRN_CODE"].Columns["ParentId"], false);
DataRelation dr2 = new DataRelation("SecondRelation", ds.Tables["TRN_CODE"].Columns["ChildId"], ds.Tables["TRN_OPERATIONS"].Columns["Trn_Id"], false);

ds.Relations.Add(dr);
ds.Relations.Add(dr2);
return ds;
}

private DataTable CreateGridDataSourceForModules(string tableName)
{
// Create a new DataTable.
System.Data.DataTable table = new DataTable(tableName);
// Declare variables for DataColumn and DataRow objects.
DataColumn column;
DataRow row;

// Create new DataColumn, set DataType,
// ColumnName and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "id";
column.ReadOnly = true;
// Add the Column to the DataColumnCollection.
table.Columns.Add(column);

// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "Item";
column.AutoIncrement = false;
column.Caption = "Item";
column.ReadOnly = false;
column.Unique = false;
// Add the column to the table.
table.Columns.Add(column);

// Create third column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "Data";
column.AutoIncrement = false;
column.Caption = "Data";
//column. = false;
column.Unique = false;
// Add the column to the table.
table.Columns.Add(column);

column = new DataColumn();
column.DataType = System.Type.GetType("System.Boolean");
column.ColumnName = "View";
column.AutoIncrement = false;
column.Caption = "View";
//column.ReadOnly = false;
column.Unique = false;
column.DefaultValue = false;
// Add the column to the table.
table.Columns.Add(column);


column = new DataColumn();
column.DataType = System.Type.GetType("System.Boolean");
column.ColumnName = "Update";
column.AutoIncrement = false;
//column.Caption = "Update";
column.ReadOnly = false;
column.Unique = false;
column.DefaultValue = false;
// Add the column to the table.
table.Columns.Add(column);


column = new DataColumn();
column.DataType = System.Type.GetType("System.Boolean");
column.ColumnName = "Delete";
column.AutoIncrement = false;
column.Caption = "Delete";
// column.ReadOnly = false;
column.Unique = false;
column.DefaultValue = false;
// Add the column to the table.
table.Columns.Add(column);


column = new DataColumn();
column.DataType = System.Type.GetType("System.Boolean");
column.ColumnName = "Save";
column.AutoIncrement = false;
column.Caption = "Save";
column.ReadOnly = false;
column.Unique = false;
column.DefaultValue = false;
// Add the column to the table.
table.Columns.Add(column);
// Make the ID column the primary key column.

DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = table.Columns["id"];
table.PrimaryKey = PrimaryKeyColumns;

DataTable Modules = objRoleTree.GetAllModules();
for (int i = 0; i < Modules.Rows.Count; i++)
{
row = table.NewRow();
row["id"]= Modules.Rows[i]["MODULE_CODE"].ToString();
row["Item"] = Modules.Rows[i]["DISPLAY_LABEL"].ToString();
row["Data"] = "Data " + i;
table.Rows.Add(row);

}

return table;

}

private DataTable CreateGridDataSourceForSubModules(string tableName, bool duplicate)
{


DataTable SubModules = Trn_Oprations.GetAllTrnsList();
// Create a new DataTable.
System.Data.DataTable table = new DataTable(tableName);
// Declare variables for DataColumn and DataRow objects.
DataColumn column;
DataRow row;

// Create new DataColumn, set DataType,
// Create First column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
//column.ColumnName = "Data";
column.ColumnName = "ChildId";
column.AutoIncrement = false;
column.Caption = "ChildId";
column.ReadOnly = false;
column.Unique = false;
// Add the column to the table.
table.Columns.Add(column);


// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "Item";
column.AutoIncrement = false;
column.Caption = "Item";
column.ReadOnly = false;
column.Unique = false;
// Add the column to the table.
table.Columns.Add(column);


// ColumnName and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "ParentId";
column.ReadOnly = true;
// Add the Column to the DataColumnCollection.
table.Columns.Add(column);

column = new DataColumn();
column.DataType = System.Type.GetType("System.Boolean");
column.ColumnName = "ChView";
column.AutoIncrement = false;
column.Caption = "View";
//column.ReadOnly = false;
column.Unique = false;
column.DefaultValue = false;
// Add the column to the table.
table.Columns.Add(column);


column = new DataColumn();
column.DataType = System.Type.GetType("System.Boolean");
column.ColumnName = "ChUpdate";
column.AutoIncrement = false;
//column.Caption = "Update";
column.ReadOnly = false;
column.Unique = false;
column.DefaultValue = false;
// Add the column to the table.
table.Columns.Add(column);


column = new DataColumn();
column.DataType = System.Type.GetType("System.Boolean");
column.ColumnName = "ChDelete";
column.AutoIncrement = false;
column.Caption = "Delete";
// column.ReadOnly = false;
column.Unique = false;
column.DefaultValue = false;
// Add the column to the table.
table.Columns.Add(column);


column = new DataColumn();
column.DataType = System.Type.GetType("System.Boolean");
column.ColumnName = "ChSave";
column.AutoIncrement = false;
column.Caption = "Save";
column.ReadOnly = false;
column.Unique = false;
column.DefaultValue = false;
// Add the column to the table.
table.Columns.Add(column);

for (int j = 0; j < SubModules.Rows.Count; j++)
{
string Trn_id = SubModules.Rows[j]["Trn_Id"].ToString();
DataTable GetTrnOperationsByTrnId = Trn_Oprations.GetOperationsByTrn(Trn_id);

//for (int u = 0; u < GetTrnOperationsByTrnId.Rows.Count; u++)
//{
// BoundCheckBoxField field = new BoundCheckBoxField(true);
// column = new DataColumn();
// field.Key = "Discontinued" + u + 1;
// field.Header.Text = "Discontinued" + u;
// field.DataFieldName = "Discontinued" + u;
// this.WebHierarchicalDataGrid1.
// this.WebHierarchicalDataGrid1.Columns.Add(field);
// // column.Columns.Add(field);
//}
}

// Make the ID column the primary key column.
if (!duplicate)
{
DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = table.Columns["id"];
table.PrimaryKey = PrimaryKeyColumns;
}
else
{

DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = table.Columns["ChildId"];
table.PrimaryKey = PrimaryKeyColumns;
}


for (int i = 0; i < SubModules.Rows.Count; i++)
{
row = table.NewRow();
string a = SubModules.Rows[i]["MODULE_CODE"].ToString();
row["ParentId"] = Convert.ToInt32(a);
row["Item"] = SubModules.Rows[i]["Menu_Label"].ToString();
row["ChildId"] =Convert.ToInt32(SubModules.Rows[i]["Trn_Id"].ToString());
table.Rows.Add(row);

}
//for (int i = 0; i <= numOfRecords; i++)
//{
// row = table.NewRow();
// row["id"] = i;
// row["Item"] = i + 2;
// row["Data"] = "Data " + i;
// table.Rows.Add(row);

// if (duplicate)
// {
// row = table.NewRow();
// row["id"] = i;
// row["Item"] = i + 20;
// row["Data"] = "Data " + i + 2;
// table.Rows.Add(row);

// row = table.NewRow();
// row["id"] = i;
// row["Item"] = i + 30;
// row["Data"] = "Data " + i + 3;
// table.Rows.Add(row);
// }
//}


return table;

}

private DataTable CreateTrnOperations(string tableName, bool duplicate)
{


DataTable Operations = Trn_Oprations.GetTrnOperations();
// Create a new DataTable.
System.Data.DataTable table = new DataTable(tableName);
// Declare variables for DataColumn and DataRow objects.
DataColumn column;
DataRow row;

// Create new DataColumn, set DataType,
// Create First column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
//column.ColumnName = "Data";
column.ColumnName = "Trn_Id";
column.AutoIncrement = false;
column.Caption = "Trn_Id";
column.ReadOnly = false;
column.Unique = false;
// Add the column to the table.
table.Columns.Add(column);


// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "Operation_ID";
column.AutoIncrement = false;
column.Caption = "Operation_ID";
column.ReadOnly = false;
column.Unique = false;
// Add the column to the table.
table.Columns.Add(column);

// Make the ID column the primary key column.
//if (!duplicate)
//{
// DataColumn[] PrimaryKeyColumns = new DataColumn[1];
// PrimaryKeyColumns[0] = table.Columns["id"];
// table.PrimaryKey = PrimaryKeyColumns;
//}
//else
//{

// DataColumn[] PrimaryKeyColumns = new DataColumn[1];
// PrimaryKeyColumns[0] = table.Columns["ChildId"];
// table.PrimaryKey = PrimaryKeyColumns;
//}


for (int i = 0; i < Operations.Rows.Count; i++)
{
row = table.NewRow();
string a = Operations.Rows[i]["TRN_ID"].ToString();
row["Trn_Id"] = Convert.ToInt32(a);
row["Operation_ID"] = Operations.Rows[i]["OPR_ID"].ToString();
table.Rows.Add(row);

}
//for (int i = 0; i <= numOfRecords; i++)
//{
// row = table.NewRow();
// row["id"] = i;
// row["Item"] = i + 2;
// row["Data"] = "Data " + i;
// table.Rows.Add(row);

// if (duplicate)
// {
// row = table.NewRow();
// row["id"] = i;
// row["Item"] = i + 20;
// row["Data"] = "Data " + i + 2;
// table.Rows.Add(row);

// row = table.NewRow();
// row["id"] = i;
// row["Item"] = i + 30;
// row["Data"] = "Data " + i + 3;
// table.Rows.Add(row);
// }
//}


return table;

}

and my Front-end side:

<ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" AutoGenerateBands="False"
AutoGenerateColumns="False" DataKeyFields="id" DataMember="Module" EnableViewState="true"
ViewStateMode="Enabled"
InitialExpandDepth="3" InitialDataBindDepth="3"
Height="350px" Width="900px" >
<%--<ClientEvents Initialize="InitializHandler" Click="ClickHandler"/>--%>
<%-- <AutoPostBackFlags RowSelectionChanged="false" />--%>
<%--<AutoPostBackFlags CellSelectionChanged="Of" />--%>
<Columns>
<ig:BoundDataField DataFieldName="id" Hidden="false" DataType="System.Int32" Key="id" Width="100px">
<Header Text="Module ID" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="Item" DataType="System.String" Key="Item">
<Header Text="Module Description" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="Data" Hidden="true" DataType="System.String" Key="Data">
<Header Text="Operations" />
</ig:BoundDataField>
<ig:BoundCheckBoxField DataFieldName="View" DataType="System.Boolean" Key="View">
<Header Text="View" />
</ig:BoundCheckBoxField>
<ig:BoundCheckBoxField DataFieldName="Update" DataType="System.Boolean" Key="Update">
<Header Text="Update" />
</ig:BoundCheckBoxField>
<ig:BoundCheckBoxField DataFieldName="Delete" DataType="System.Boolean" Key="Delete">
<Header Text="Delete" />
</ig:BoundCheckBoxField>
<ig:BoundCheckBoxField DataFieldName="Save" DataType="System.Boolean" Key="Save">
<Header Text="Save" />
</ig:BoundCheckBoxField>
</Columns>

<Bands>
<ig:Band AutoGenerateColumns="False" DataKeyFields="Item" DataMember="TRN_CODE" Key="ChildBand_0">
<Columns>

<ig:BoundDataField DataFieldName="ChildId" Hidden="false" DataType="System.Int32" Key="DataCh">
<Header Text="Child Id" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="Item" DataType="System.String" Key="ItemCh">
<Header Text="Child Item" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="ParentId" Hidden="false" DataType="System.Int32" Key="idCh">
<Header Text="Parent ID" />
</ig:BoundDataField>
<ig:BoundCheckBoxField DataFieldName="ChView" DataType="System.Boolean" Key="ChView">
<Header Text="View" />
</ig:BoundCheckBoxField>
<ig:BoundCheckBoxField DataFieldName="ChUpdate" DataType="System.Boolean" Key="ChUpdate">
<Header Text="Update" />
</ig:BoundCheckBoxField>
<ig:BoundCheckBoxField DataFieldName="ChDelete" DataType="System.Boolean" Key="ChDelete">
<Header Text="Delete" />
</ig:BoundCheckBoxField>
<ig:BoundCheckBoxField DataFieldName="ChSave" DataType="System.Boolean" Key="ChSave">
<Header Text="Save" />
</ig:BoundCheckBoxField>

</Columns>

<Behaviors>
<ig:EditingCore BatchUpdating="True">
<Behaviors>
<ig:RowAdding/>
<ig:RowDeleting/>
<ig:CellEditing/>
</Behaviors>
</ig:EditingCore>
<%--<ig:EditingCore AutoCRUD="false">
<Behaviors>
<ig:CellEditing>
<ColumnSettings>
<ig:EditingColumnSetting ColumnKey="ItemCh" ReadOnly="true" />
</ColumnSettings>

</ig:CellEditing>
</Behaviors>
</ig:EditingCore>--%>
</Behaviors>
</ig:Band>
</Bands>


<Behaviors>

<ig:Selection CellClickAction="Row" CellSelectType="None" RowSelectType="Single">
<AutoPostBackFlags CellSelectionChanged="false" RowSelectionChanged="false" ColumnSelectionChanged="false" />
<%--<AutoPostBackFlags RowSelectionChanged="false" />--%>

</ig:Selection>
<ig:Activation>
</ig:Activation>
<ig:EditingCore BatchUpdating="True"/>

<%--<ig:EditingCore>
<Behaviors>

<ig:CellEditing>
<ColumnSettings>

<ig:EditingColumnSetting ColumnKey="Item" ReadOnly="true" />
</ColumnSettings>

</ig:CellEditing>
</Behaviors>
</ig:EditingCore>--%>
</Behaviors>
</ig:WebHierarchicalDataGrid>

Parents
No Data
Reply
  • 1300
    Offline posted

    Hello Muhammad,  

    I noticed that there is another forum thread regarding the same query. Please, keep in mind that according to our support policy we handle singe thread per issues. This helps us ensure that all issues are addressed and handled correctly. 

    Please have a look at this forum thread where I have already provided an answer and let me know if you have any additional questions.  

    Thank you for using Infragistics components.

    Regards,

    Monika Kirkova,

    Infragistics

Children
No Data