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

How to put the grid items of a Hierarchy Model RadGrid in edit mode

8 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Herman Gouw
Top achievements
Rank 2
Herman Gouw asked on 21 Sep 2010, 08:33 AM
Hi,

Can someone please help me with the following problem?

In my current project I have an advanced hierarchy model of Telerik RadGrid.

I need to set the CheckBoxes grid items into Edit Mode similar to the following http://www.gouw.ws/EditGrouping.aspx

I followed the documentation as given here "Put all items in edit mode without additional rebind"

However, it does not seem to work.

The web page is available on http://www.gouw.ws/HierarchyWithDS.aspx

The code are given as follows:

ASPX
<telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="False" AutoGenerateHierarchy="True" AllowMultiRowEdit="true" Width="70%" OnNeedDataSource="RadGrid1_NeedDataSource" runat="server">
    <ClientSettings EnableAlternatingItems="false">
        <Scrolling UseStaticHeaders="true" />
    </ClientSettings>
     <MasterTableView DataKeyNames="CategoryId" EditMode="InPlace" TableLayout="Fixed">
        <DetailTables>
            <telerik:GridTableView DataKeyNames="CategoryId,TypeId" runat="server">
                <ParentTableRelation>
                     <telerik:GridRelationFields DetailKeyField="CategoryId" MasterKeyField="CategoryId" />
                </ParentTableRelation>
                <DetailTables>
                    <telerik:GridTableView DataKeyNames="TypeId,ContactName" runat="server">
                        <ParentTableRelation>
                            <telerik:GridRelationFields DetailKeyField="TypeId" MasterKeyField="TypeId" />
                        </ParentTableRelation>
                        <Columns>
                            <telerik:GridBoundColumn DataField="TypeId" DataType="System.String" ReadOnly="true" Visible="false" UniqueName="TypeId" />
                            <telerik:GridBoundColumn DataField="ContactName" DataType="System.String" HeaderText="Contact Name" ReadOnly="true" UniqueName="ContactName" />
                            <telerik:GridCheckBoxColumn DataField="Email" DataType="System.Boolean" HeaderText="Email" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ReadOnly="false" UniqueName="Email" />
                            <telerik:GridCheckBoxColumn DataField="SMS" DataType="System.Boolean" HeaderText="SMS" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ReadOnly="false" UniqueName="SMS" />
                            <telerik:GridCheckBoxColumn DataField="NotifyByEmail" DataType="System.Boolean" HeaderText="Notify By Email" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ReadOnly="false" UniqueName="NotifyByEmail" />
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
                <Columns>
                    <telerik:GridBoundColumn DataField="CategoryId" DataType="System.String" ReadOnly="true" Visible="false" UniqueName="CategoryId" />
                    <telerik:GridBoundColumn DataField="TypeId" DataType="System.String" ReadOnly="true" Visible="false" UniqueName="TypeId" />
                    <telerik:GridBoundColumn DataField="TypeName" DataType="System.String" HeaderText="Type Name" ReadOnly="true" UniqueName="TypeName" />
                    <telerik:GridCheckBoxColumn DataField="NoEncryption" DataType="System.Boolean" HeaderText="Encryption Not Required" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ReadOnly="false" UniqueName="NoEncryption" />
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
        <Columns>
            <telerik:GridBoundColumn DataField="CategoryId" DataType="System.String" ReadOnly="true" Visible="false" UniqueName="CategoryId" />
            <telerik:GridBoundColumn DataField="CategoryName" DataType="System.String" HeaderText="Category Name" ReadOnly="true" UniqueName="CategoryName" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#
public partial class HierarchyWithDS : System.Web.UI.Page
{
    private DataSet _dataSet = null;
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (_dataSet == null) _dataSet = CreateDataSet();
            Session["DATASET"] = _dataSet;
        }
        else
        {
            _dataSet = (DataSet)Session["DATASET"];
        }
 
        SetEditMode();
    }
 
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        this.RadGrid1.DataSource = _dataSet;
    }
 
    private void SetEditMode()
    {
        int size = 0;
        for (int i = 0; i < _dataSet.Tables.Count; i++)
        {
            size += _dataSet.Tables[i].Rows.Count;
        }
        for (int i = 0; i < size; i++)
        {
            this.RadGrid1.EditIndexes.Add(i);
        }
    }
 
    private DataSet CreateDataSet()
    {
        DataSet dataSet = new DataSet();
 
        // Category table
        DataTable dtCategory = new DataTable("Category");
        dtCategory.Columns.Add("CategoryId", typeof(string));
        dtCategory.Columns.Add("CategoryName", typeof(string));
        dataSet.Tables.Add(dtCategory);
        foreach (Category category in Category.Load())
        {
            DataRow row = dataSet.Tables["Category"].NewRow();
            row["CategoryId"] = category.CategoryId;
            row["CategoryName"] = category.CategoryName;
            dataSet.Tables["Category"].Rows.Add(row);
        }
 
        // Type table
        DataTable dtType = new DataTable("Type");
        dtType.Columns.Add("CategoryId", typeof(string));
        dtType.Columns.Add("TypeId", typeof(string));
        dtType.Columns.Add("TypeName", typeof(string));
        dtType.Columns.Add("NoEncryption", typeof(bool));
        dataSet.Tables.Add(dtType);
        foreach (Category category in Category.Load())
        {
            foreach (Type type in Type.Load())
            {
                if (category.CategoryId == type.CategoryId)
                {
                    DataRow row = dataSet.Tables["Type"].NewRow();
                    row["CategoryId"] = type.CategoryId;
                    row["TypeId"] = type.TypeId;
                    row["TypeName"] = type.TypeName;
                    row["NoEncryption"] = type.NoEncryption;
                    dataSet.Tables["Type"].Rows.Add(row);
                }
            }
        }
 
        // Subscription table
        DataTable dtSubscription = new DataTable("Subscription");
        dtSubscription.Columns.Add("TypeId", typeof(string));
        dtSubscription.Columns.Add("ContactName", typeof(string));
        dtSubscription.Columns.Add("Email", typeof(bool));
        dtSubscription.Columns.Add("SMS", typeof(bool));
        dtSubscription.Columns.Add("NotifyByEmail", typeof(bool));
        dataSet.Tables.Add(dtSubscription);
        foreach (Type type in Type.Load())
        {
            foreach (Subscription subscription in Subscription.Load())
            {
                if (type.TypeId == subscription.TypeId)
                {
                    DataRow row = dataSet.Tables["Subscription"].NewRow();
                    row["TypeId"] = subscription.TypeId;
                    row["ContactName"] = subscription.ContactName;
                    row["Email"] = subscription.Email;
                    row["SMS"] = subscription.SMS;
                    row["NotifyByEmail"] = subscription.NotifyByEmail;
                    dataSet.Tables["Subscription"].Rows.Add(row);
                }
            }
        }
 
        // Table relations
        dataSet.Relations.Add(new DataRelation("Category-Type", dataSet.Tables["Category"].Columns["CategoryId"], dataSet.Tables["Type"].Columns["CategoryId"]));
        dataSet.Relations.Add(new DataRelation("Type-Subscription", dataSet.Tables["Type"].Columns["TypeId"], dataSet.Tables["Subscription"].Columns["TypeId"]));
 
        return dataSet;
    }
}
 
public class Category
{
    public string CategoryId { get; set; }
    public string CategoryName { get; set; }
 
    public Category(string categoryId = null, string categoryName = null)
    {
        CategoryId = categoryId;
        CategoryName = categoryName;
    }
 
    public static List<Category> Load()
    {
        List<Category> category = new List<Category>();
        category.Add(new Category("NEM_STATEMENTS", "NEM Statements"));
        return category;
    }
}
 
public class Type
{
    public string CategoryId { get; set; }
    public string TypeId { get; set; }
    public string TypeName { get; set; }
    public bool NoEncryption { get; set; }
 
    public Type(string categoryId = null, string typeId = null, string typeName = null, bool noEncryption = false)
    {
        CategoryId = categoryId;
        TypeId = typeId;
        TypeName = typeName;
        NoEncryption = noEncryption;
    }
 
    public static List<Type> Load()
    {
        List<Type> type = new List<Type>();
        type.Add(new Type("NEM_STATEMENTS", "NEM_STMT_PRELIM", "Preliminary"));
        type.Add(new Type("NEM_STATEMENTS", "NEM_STMT_FINAL", "Final"));
        type.Add(new Type("NEM_STATEMENTS", "NEM_STMT_REVISION", "Revision"));
        return type;
    }
}
 
public class Subscription
{
    public string TypeId { get; set; }
    public string ContactName { get; set; }
    public bool Email { get; set; }
    public bool SMS { get; set; }
    public bool NotifyByEmail { get; set; }
 
    public Subscription(string typeId = null, string contactName = null, bool email = false, bool sms = false, bool notifyByEmail = false)
    {
        TypeId = typeId;
        ContactName = contactName;
        Email = email;
        SMS = sms;
        NotifyByEmail = notifyByEmail;
    }
 
    public static List<Subscription> Load()
    {
        List<Subscription> subscription = new List<Subscription>();
        subscription.Add(new Subscription("NEM_STMT_PRELIM", "Inger Wills"));
        subscription.Add(new Subscription("NEM_STMT_PRELIM", "Keith Armstrong"));
        subscription.Add(new Subscription("NEM_STMT_PRELIM", "Lance McMinn"));
        subscription.Add(new Subscription("NEM_STMT_FINAL", "Inger Wills"));
        subscription.Add(new Subscription("NEM_STMT_FINAL", "Keith Armstrong"));
        subscription.Add(new Subscription("NEM_STMT_FINAL", "Lance McMinn"));
        subscription.Add(new Subscription("NEM_STMT_REVISION", "Inger Wills"));
        subscription.Add(new Subscription("NEM_STMT_REVISION", "Keith Armstrong"));
        subscription.Add(new Subscription("NEM_STMT_REVISION", "Lance McMinn"));
        return subscription;
    }
}

8 Answers, 1 is accepted

Sort by
0
Herman Gouw
Top achievements
Rank 2
answered on 22 Sep 2010, 11:05 AM
Hi,

Can someone please help me with this problem?

Thanks,
Herman
0
Mira
Telerik team
answered on 23 Sep 2010, 02:50 PM
Hello Herman,

Please use the following code to put all the items in a three-level hierarchy RadGrid in edit-mode:
protected void Page_Load(object sender, EventArgs e)
{
    for (int i = 0; i < RadGrid1.PageSize; i++)
    {
        RadGrid1.EditIndexes.Add(i);
        for (int j = 0; j < RadGrid1.MasterTableView.DetailTables[0].PageSize; j++)
        {
            RadGrid1.EditIndexes.Add(i, 0, j);
            for (int k = 0; k < RadGrid1.MasterTableView.DetailTables[0].DetailTables[0].PageSize; k++)
            {
                RadGrid1.EditIndexes.Add(i, 0, j, 0, k);
            }
        }
    }
}

I hope this helps.

Sincerely yours,
Mira
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Herman Gouw
Top achievements
Rank 2
answered on 23 Sep 2010, 05:58 PM
Hi Mira,

Thanks for your reply.

I have tried what you suggested and the webpage is available on http://www.gouw.ws/HierarchyWithDS.aspx
but it does NOT work as I intended, i.e.:

- the grid is initially displayed as expanded but with "No child records to display."
  ---> How can I make the grid to be initially displayed as collapsed?

- when I collapsed the items and expand them again, all the editable check boxes are displayed under each line with Update and Cancel links. This is not what I want.
   ---> How can I display make them as in-line editable checkboxes similar to http://www.gouw.ws/EditGrouping.aspx ?

The modified ASPX and C# are given below:

ASPX
<telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="False" AutoGenerateHierarchy="True" AllowMultiRowEdit="true" Width="70%" OnNeedDataSource="RadGrid1_NeedDataSource" runat="server">
    <ClientSettings EnableAlternatingItems="false">
        <Scrolling UseStaticHeaders="true" />
    </ClientSettings>
    <MasterTableView DataKeyNames="CategoryId" EditMode="InPlace" TableLayout="Fixed">
        <DetailTables>
            <telerik:GridTableView DataKeyNames="CategoryId,TypeId" EditMode="InPlace" runat="server">
                <ParentTableRelation>
                     <telerik:GridRelationFields DetailKeyField="CategoryId" MasterKeyField="CategoryId" />
                </ParentTableRelation>
                <DetailTables>
                    <telerik:GridTableView DataKeyNames="TypeId,ContactName" EditMode="InPlace" runat="server">
                        <ParentTableRelation>
                            <telerik:GridRelationFields DetailKeyField="TypeId" MasterKeyField="TypeId" />
                        </ParentTableRelation>
                        <Columns>
                            <telerik:GridBoundColumn DataField="TypeId" DataType="System.String" ReadOnly="true" Visible="false" UniqueName="TypeId" />
                            <telerik:GridBoundColumn DataField="ContactName" DataType="System.String" HeaderText="Contact Name" ReadOnly="true" UniqueName="ContactName" />
                            <telerik:GridCheckBoxColumn DataField="Email" DataType="System.Boolean" HeaderText="Email" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ReadOnly="false" UniqueName="Email" />
                            <telerik:GridCheckBoxColumn DataField="SMS" DataType="System.Boolean" HeaderText="SMS" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ReadOnly="false" UniqueName="SMS" />
                            <telerik:GridCheckBoxColumn DataField="NotifyByEmail" DataType="System.Boolean" HeaderText="Notify By Email" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ReadOnly="false" UniqueName="NotifyByEmail" />
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
                <Columns>
                    <telerik:GridBoundColumn DataField="CategoryId" DataType="System.String" ReadOnly="true" Visible="false" UniqueName="CategoryId" />
                    <telerik:GridBoundColumn DataField="TypeId" DataType="System.String" ReadOnly="true" Visible="false" UniqueName="TypeId" />
                    <telerik:GridBoundColumn DataField="TypeName" DataType="System.String" HeaderText="Type Name" ReadOnly="true" UniqueName="TypeName" />
                    <telerik:GridCheckBoxColumn DataField="NoEncryption" DataType="System.Boolean" HeaderText="Encryption Not Required" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ReadOnly="false" UniqueName="NoEncryption" />
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
        <Columns>
            <telerik:GridBoundColumn DataField="CategoryId" DataType="System.String" ReadOnly="true" Visible="false" UniqueName="CategoryId" />
            <telerik:GridBoundColumn DataField="CategoryName" DataType="System.String" HeaderText="Category Name" ReadOnly="true" UniqueName="CategoryName" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>


C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        if (_dataSet == null) _dataSet = CreateDataSet();
        Session["DATASET"] = _dataSet;
    }
    else
    {
        _dataSet = (DataSet)Session["DATASET"];
    }
  
    for (int i = 0; i < RadGrid1.PageSize; i++)
    {
        RadGrid1.EditIndexes.Add(i);
        for (int j = 0; j < RadGrid1.MasterTableView.DetailTables[0].PageSize; j++)
        {
            RadGrid1.EditIndexes.Add(i, 0, j);
            for (int k = 0; k < RadGrid1.MasterTableView.DetailTables[0].DetailTables[0].PageSize; k++)
            {
                RadGrid1.EditIndexes.Add(i, 0, j, 0, k);
            }
        }
    }
}
0
Herman Gouw
Top achievements
Rank 2
answered on 27 Sep 2010, 02:03 AM
Hi,

Can someone please help me with this problem?

I am stuck with current project because of this.

I need to know if it is possible to get in line editable checkboxes (i.e. without Update and Cancel links) in a Hierarchy model RadGrid.

Need to have the following http://www.gouw.ws/HierarchyWithDS.aspx

similar to http://www.gouw.ws/EditGrouping.aspx

Please read my latest comments.

Thanks,
Herman
0
Herman Gouw
Top achievements
Rank 2
answered on 27 Sep 2010, 07:53 AM
Hi,

I just looked very closely at the Telerik Forums and it turned out somebody else has encountered identical problem as mine.

Please look at the following thread
http://www.telerik.com/community/forums/aspnet-ajax/grid/can-t-set-to-edit-mode-automatically-in-hierarchical-grid.aspx

Regards,
Herman

0
Mira
Telerik team
answered on 27 Sep 2010, 02:06 PM
Hello Herman,

Have you tried the approach from the forum thread you mentioned?

Please follow it and let me know how it goes.

Sincerely yours,
Mira
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Herman Gouw
Top achievements
Rank 2
answered on 27 Sep 2010, 11:58 PM
Hi Mira,

The problem in the thread mentioned has NOT been fixed. Exactly just like mine.

Please read it closely.

Regards,
Herman

0
Mira
Telerik team
answered on 30 Sep 2010, 10:56 AM
Hello Herman,

I have prepared a sample project demonstrating how the functionality requested in the Can't set to edit mode automatically in hierarchical grid forum thread can be implemented. You can find it attached to this message.

I hope this helps.

Best wishes,
Mira
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Herman Gouw
Top achievements
Rank 2
Answers by
Herman Gouw
Top achievements
Rank 2
Mira
Telerik team
Share this question
or