I have a self-referencing hierarchical grid set up. I need to have insert functionality available for any hierarchical level. When a row is expanded to show the children records I need to hide the non selected parent records and disable the selected parent. This is working correctly. The issue I need guideance on is that I also need to suppress the option to insert a row into the parent's hierarchical level if a child is open. Otherwise, at each level of hierarchy there is an option to insert a record which is confusing to the users since we are hiding the rows for that hierarchical level. I'm sure looking at the code could make this a little more clear . . .
This is a simple self-refrencing hierarchical grid with automatic inserts enabled:
Here is the ItemCommand which is suppressing the non selected hierarchical rows. There is a block of noted out code in the middle of this which shows a couple of things I have tried without success.
Please let me know if there is a way to do this. My next step was going to be to throw out the self-referencing and add detail tables for each level of hierarchy, but that seems down right silly.
Thanks,
Casey
This is a simple self-refrencing hierarchical grid with automatic inserts enabled:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
Skin
=
"Web20"
OnItemCreated
=
"RadGrid1_ItemCreated"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
OnColumnCreated
=
"RadGrid1_ColumnCreated"
AutoGenerateColumns
=
"False"
ShowStatusBar
=
"True"
CellSpacing
=
"0"
GridLines
=
"None"
AllowAutomaticInserts
=
"True"
>
<
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_Default"
></
HeaderContextMenu
>
<
MasterTableView
DataKeyNames
=
"CATEGORY_CDE, PARENT_CDE"
ShowHeader
=
"true"
HierarchyDefaultExpanded
=
"false"
AllowSorting
=
"true"
CommandItemDisplay
=
"Bottom"
editmode
=
"InPlace"
InsertItemDisplay
=
"Bottom"
>
<
SelfHierarchySettings
KeyName
=
"CATEGORY_CDE"
ParentKeyName
=
"PARENT_CDE"
/>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
AddNewRecordText
=
"Add New Category"
></
CommandItemSettings
>
<
Columns
>
<
telerik:GridExpandColumn
FilterControlAltText
=
"Filter ExpandColumn column"
Visible
=
"True"
>
</
telerik:GridExpandColumn
>
<
telerik:GridEditCommandColumn
UniqueName
=
"UpdateColumn"
FilterControlAltText
=
"Filter EditCommandColumn column"
Visible
=
"True"
EditText
=
""
InsertText
=
""
CancelText
=
""
ButtonType
=
"ImageButton"
EditImageUrl
=
"../images/blank.gif"
>
</
telerik:GridEditCommandColumn
>
<
telerik:GridBoundColumn
DataField
=
"Category_Cde"
UniqueName
=
"Category_Cde"
Visible
=
"true"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Parent_cde"
UniqueName
=
"Parent_cde"
Visible
=
"true"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
Visible
=
"True"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
></
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
AllowExpandCollapse
=
"true"
/>
<
FilterMenu
EnableImageSprites
=
"False"
></
FilterMenu
>
</
telerik:RadGrid
>
Here is the ItemCommand which is suppressing the non selected hierarchical rows. There is a block of noted out code in the middle of this which shows a couple of things I have tried without success.
Protected
Sub
RadGrid1_ItemCommand(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridCommandEventArgs)
Handles
RadGrid1.ItemCommand
Dim
itemKey
As
String
'Inactivates non selected hierarchy levels
If
(e.CommandName = RadGrid.ExpandCollapseCommandName)
Then
Dim
currentItem
As
GridDataItem =
DirectCast
(e.Item, GridDataItem)
Dim
currentRowIndex
As
Integer
= currentItem.ItemIndex
Dim
currentCatKey
As
String
= currentItem.GetDataKeyValue(
"CATEGORY_CDE"
).ToString()
Dim
currentParentKey
As
String
= currentItem.GetDataKeyValue(
"PARENT_CDE"
).ToString()
If
(
Not
currentItem.Expanded)
Then
'If an item is expanded then hide the other rows at that level
For
Each
ditem
As
GridDataItem
In
RadGrid1.Items
itemKey = ditem.GetDataKeyValue(
"PARENT_CDE"
).ToString()
If
currentRowIndex <> ditem.ItemIndex
And
currentParentKey = ditem.GetDataKeyValue(
"PARENT_CDE"
).ToString()
Then
'Trying to find the right way to suppress the option to add categories for unopened levels
'RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = False
'RadGrid1.MasterTableView.CommandItemSettings.ShowRefreshButton = False
' RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None
'RadGrid1.AllowAutomaticInserts = False
'Enables the fields for the row
EnableDisableItem(ditem,
True
)
ditem.Visible = False
Else
'Disables the fields for the row
EnableDisableItem(ditem,
False
)
End
If
Next
Else
For
Each
ditem
As
GridDataItem
In
RadGrid1.Items
itemKey = ditem.GetDataKeyValue(
"PARENT_CDE"
).ToString()
If
currentParentKey = ditem.GetDataKeyValue(
"PARENT_CDE"
).ToString()
Then
ditem.Visible =
True
'Enables fields for row
EnableDisableItem(ditem,
True
)
End
If
Next
End
If
End
If
If
(e.CommandName =
"PerformInsert"
)
Then
e.Canceled =
True
Dim
dgi
As
GridDataInsertItem = TryCast(e.Item, GridDataInsertItem)
updateCategory(
"AddCat"
, dgi)
RadGrid1.EditIndexes.Clear()
RadGrid1.Rebind()
End
If
rbtnSave.Visible =
True
End
Sub
Please let me know if there is a way to do this. My next step was going to be to throw out the self-referencing and add detail tables for each level of hierarchy, but that seems down right silly.
Thanks,
Casey