This is a migrated thread and some comments may be shown as answers.

Self-referencing Hierarchy and checkbox

3 Answers 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Djefri
Top achievements
Rank 1
Djefri asked on 05 Nov 2010, 07:48 AM
<telerik:RadGrid ID="RadGrid1" runat="server" OnColumnCreated="RadGrid1_ColumnCreated" Skin="Office2007" Width="600px" OnItemCreated="RadGrid1_ItemCreated" OnItemDataBound="RadGrid1_ItemDataBound" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource">
  <MasterTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" AllowSorting="true" DataKeyNames="mnid, mnparent,mnnamein">
    <SelfHierarchySettings ParentKeyName="mnparent" KeyName="mnid" />
        <Columns>
        <telerik:GridBoundColumn DataField="mnnamein" HeaderText="Menu"UniqueName="mnnamein"
           HeaderStyle-Width="350px"></telerik:GridBoundColumn>
        <telerik:GridTemplateColumn  UniqueName="CheckBoxTemplateColumn" HeaderText="Open">
        <ItemTemplate>
            <asp:CheckBox id="CheckBox1" runat="server"></asp:CheckBox>
        </ItemTemplate>
        </telerik:GridTemplateColumn>
        </Columns>
   </MasterTableView>
   <ClientSettings AllowExpandCollapse="true" />
</telerik:RadGrid>
I have grid like this(for picture in my attachement). The problem, if I select the parent checkbok then details checkbok also select and if I select details checkbok then parent checkbox also select.

How to doing like that??

thanks

3 Answers, 1 is accepted

Sort by
0
Djefri
Top achievements
Rank 1
answered on 06 Nov 2010, 04:30 AM
if grid have one parent group it is easy, but if grid has more than one parent
How ...?

this is code for One Parent :

<telerik:RadGrid ID="RadGrid1" runat="server" OnColumnCreated="RadGrid1_ColumnCreated" Skin="Office2007" Width="600px"
OnItemCreated="RadGrid1_ItemCreated" OnItemDataBound="RadGrid1_ItemDataBound" AutoGenerateColumns="false"
OnNeedDataSource="RadGrid1_NeedDataSource" AllowMultiRowSelection="true">
<MasterTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" AllowSorting="true" Name="asd" DataKeyNames="mnid, mnparent,mnnameen">
<SelfHierarchySettings ParentKeyName="mnparent" KeyName="mnid" />
<Columns>
<telerik:GridBoundColumn DataField="mnnameen" HeaderText="Menu" UniqueName="mnnameen" HeaderStyle-Width="350px"></telerik:GridBoundColumn>
<telerik:GridTemplateColumn  UniqueName="CheckBoxTemplateColumn" HeaderText="Open">
<ItemTemplate>
<asp:CheckBox id="CheckBox1" OnCheckedChanged="ToggleRowSelection" runat="server"></asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowExpandCollapse="true" EnableRowHoverStyle="true">
<Selecting AllowRowSelect="True" />
<ClientEvents OnRowSelecting="RowSelecting" />
</ClientSettings>
</telerik:RadGrid>

Public Sub HideExpandColumnRecursive(ByVal tableView As GridTableView)
Dim nestedViewItems As GridItem() = tableView.GetItems(GridItemType.NestedView)
For Each nestedViewItem As GridNestedViewItem In nestedViewItems
For Each nestedView As GridTableView In nestedViewItem.NestedTableViews
nestedView.Style("border") = "0"
 
Dim MyExpandCollapseButton As Button = DirectCast(nestedView.ParentItem.FindControl("MyExpandCollapseButton"), Button)
Dim MyCBox As CheckBox = DirectCast(nestedView.ParentItem.FindControl("CheckBox1"), CheckBox)
If nestedView.Items.Count = 0 Then
If Not MyExpandCollapseButton Is Nothing Then
MyExpandCollapseButton.Style("visibility") = "hidden"
End If
nestedViewItem.Visible = False
MyCBox.Attributes.Add("onclick", "Select(this);")
Else
If Not MyExpandCollapseButton Is Nothing Then
MyExpandCollapseButton.Style.Remove("visibility")
MyCBox.Attributes.Add("onclick", "SelectAll(this);")
End If
End If
 
If nestedView.HasDetailTables Then
HideExpandColumnRecursive(nestedView)
End If
Next
Next
End Sub


function Select(CheckBoxControl) {
if (CheckBoxControl.checked == true) {
  document.getElementById("RadGrid1_ctl00_ctl04_CheckBox1").checked = true;
} else {
document.getElementById("RadGrid1_ctl00_ctl04_CheckBox1").checked = false;
           }
       }
function SelectAll(CheckBoxControl) {
if (CheckBoxControl.checked == true) {
var i;
for (i = 0; i < document.forms[0].elements.length; i++) {
if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('RadGrid1') > -1)) {
document.forms[0].elements[i].checked = true;
}
}
} else {
var i;
for (i = 0; i < document.forms[0].elements.length; i++) {
if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('RadGrid1') > -1)) {
document.forms[0].elements[i].checked = false;
}
}
}
}

Protected Sub ToggleRowSelection(ByVal sender As Object, ByVal e As EventArgs)
CType(CType(sender, CheckBox).Parent.Parent, GridItem).Selected = CType(sender, CheckBox).Checked
End Sub

for picture in my attacement
0
Djefri
Top achievements
Rank 1
answered on 08 Nov 2010, 02:45 AM
please help me...
0
Djefri
Top achievements
Rank 1
answered on 10 Nov 2010, 04:47 AM
I'll answer my own question since no one person who can answer

function CheckedChanged(CheckBoxControl) {
    var name = CheckBoxControl.id;
    var gabungan = name.split("__");
    if (gabungan[1] == 0) {
        SelectAll(CheckBoxControl);
    } else {
        SelectItem(CheckBoxControl, gabungan);
    }
}
 
function SelectAll(CheckBoxControl) {
    if (CheckBoxControl.checked == true) {
        var i;
        for (i = 0; i < document.forms[0].elements.length; i++) {
            if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('RadGrid1') > -1)) {
                document.forms[0].elements[i].checked = true;
            }
        }
    } else {
        var i;
        for (i = 0; i < document.forms[0].elements.length; i++) {
            if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('RadGrid1') > -1)) {
                document.forms[0].elements[i].checked = false;
            }
        }
    }
}
 
function SelectItem(CheckBoxControl, gabungan) {
    var i;
    for (i = gabungan[1].length - 4; i > 0; i -= 4) {
        var idcboxnya = gabungan[1].substring(0, i);
        var j;
        for (j = 0; j < document.forms[0].elements.length; j++) {
            if (CheckBoxControl.checked == true) {
                if ((document.forms[0].elements[j].type == 'checkbox') && (document.forms[0].elements[j].name.indexOf('RadGrid1') > -1)) {
                    var idcbox = document.forms[0].elements[j].id.split("__");
                    if (idcboxnya == idcbox[1]) {
                        document.forms[0].elements[j].checked = true;
                    } else {
                        var myRegExp = gabungan[1];
                        var matchPos1 = idcbox[1].search(myRegExp);
 
                        if (matchPos1 != -1) {
                            document.forms[0].elements[j].checked = true;
                        }
                    }
                }
            } else {
                if ((document.forms[0].elements[j].type == 'checkbox') && (document.forms[0].elements[j].name.indexOf('RadGrid1') > -1)) {
                    var idcbox = document.forms[0].elements[j].id.split("__");                       
                    var myRegExp = gabungan[1];
                    var matchPos1 = idcbox[1].search(myRegExp);
 
                    if (matchPos1 != -1) {
                        document.forms[0].elements[j].checked = false;
                    }
                }
            }
        }
    }
}

Public Sub HideExpandColumnRecursive(ByVal tableView As GridTableView)
    Dim nestedViewItems As GridItem() = tableView.GetItems(GridItemType.NestedView)
 
    Dim itemid As String, itemidnya As String
    For Each item As GridItem In tableView.Items
        If TypeOf item Is GridDataItem Then
            Dim dataItem As GridDataItem = CType(item, GridDataItem)
            itemid = dataItem.ClientID
            Dim data() As String = Split(itemid, "__")
            Dim checkBox As CheckBox = TryCast(dataItem("CheckBoxTemplateColumn").FindControl("CheckBox1"), CheckBox)
            itemidnya = "_" & data(1) & "__CheckBox1"
            checkBox.ID = itemidnya
        End If
    Next
 
    For Each nestedViewItem As GridNestedViewItem In nestedViewItems
        For Each nestedView As GridTableView In nestedViewItem.NestedTableViews
            nestedView.Style("border") = "0"
 
            Dim MyExpandCollapseButton As Button = DirectCast(nestedView.ParentItem.FindControl("MyExpandCollapseButton"), Button)
            'Dim MyCBox As CheckBox = DirectCast(nestedView.ParentItem.FindControl("CheckBox1"), CheckBox)
            If nestedView.Items.Count = 0 Then
                If Not MyExpandCollapseButton Is Nothing Then
                    MyExpandCollapseButton.Style("visibility") = "hidden"
                End If
                nestedViewItem.Visible = False
            Else
                If Not MyExpandCollapseButton Is Nothing Then
                    MyExpandCollapseButton.Style.Remove("visibility")
                End If
            End If
 
            If nestedView.HasDetailTables Then
                HideExpandColumnRecursive(nestedView)
            End If
        Next
    Next
End Sub

Thanks
Tags
Grid
Asked by
Djefri
Top achievements
Rank 1
Answers by
Djefri
Top achievements
Rank 1
Share this question
or