RadGridView fire RowSourceNeeded event

6 posts, 0 answers
  1. tphan
    tphan avatar
    22 posts
    Member since:
    Jun 2012

    Posted 10 Feb 2012 Link to this post

    Do you know how to fire a RowSourceNeeded event manually ?

    e.g. RowSourceNeeded(sender, new GridViewRowSourceNeededEventArgs(xxx,xxx,xxx));

    Thanks.

     

     

  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 14 Feb 2012 Link to this post

    Hello Charles,

    You can not call RowSourceNeeded event manually. To refresh the current values using RowSourceNeeded event in your RadGridView control in virtual mode, you can call the Update method of TableElement. Here is a sample:

    private void button1_Click(object sender, EventArgs e)
    {
        radGridView.TableElement.Update(GridUINotifyAction.DataChanged);
    }

    I hope this helps.

    Kind regards,
    Julian Benkov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. tphan
    tphan avatar
    22 posts
    Member since:
    Jun 2012

    Posted 16 Feb 2012 Link to this post

    That's Good !
    Further more question, if the RadGridView contains master template and chlidren templates... How can I acheive the same result as well ?
  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 20 Feb 2012 Link to this post

    Hi Charles,

    In order to refresh the ChildRows in the hierarchy mode, you should call the Refresh method of the MasterTemplate:
    radGridView.MasterTemplate.Refresh();

    I hope this helps.

    All the best,
    Julian Benkov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  5. tphan
    tphan avatar
    22 posts
    Member since:
    Jun 2012

    Posted 20 Feb 2012 Link to this post

    Hi Julian,

    I have RadGridView in hierarchy mode, I have expand the children template in several layers or levels.... but when I expand other master template.. the expansion of children template is lost. How can I keep it remain expands when master template is refresh()... since when I call refresh() for the master template, the children template become collapse =(

    As you can see in the fiqure 2, I add a new row at the bottom and call refresh() it... the master template is refresh() and it made the children template in other branch collapse.....

    or I update any upper levels...the below levels is collapse.


  6. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 23 Feb 2012 Link to this post

    Hello Charles,

    To achieve this scenario, you should save and restore the ChildRow before and after the Refresh method call using some data field like a key in a HashSet. Here is a sample:

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
     
    namespace Lab.GridView
    {
        public partial class SaveRestoreHierarchyGrid : Form
        {
            private RadGridView gridView = new RadGridView();
            private DataTable parentTable = new DataTable();
            private DataTable childTable = new DataTable();
            private Random random = new Random((int)DateTime.Now.Ticks);
            private HashSet<object> expanded = new HashSet<object>();
     
            public SaveRestoreHierarchyGrid()
            {
                InitializeComponent();
     
                gridView.Dock = DockStyle.Fill;
                this.Controls.Add(gridView);
                this.button1.BringToFront();
            }
     
            private void HierarchyGridForm_Load(object sender, EventArgs e)
            {
                LoadData();
                CreateRelationHierarchy();
            }
     
            private void CreateRelationHierarchy()
            {
                GridViewTemplate template = new GridViewTemplate();
                template.DataSource = childTable;
                gridView.Templates.Add(template);
     
                GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
                GridViewSummaryItem summaryItem = new GridViewSummaryItem("ChildValue3", "", GridAggregateFunction.Sum);
                summaryItem.FormatString = "{0:N3}";
     
                summaryRowItem.Add(summaryItem);
                template.SummaryRowsBottom.Add(summaryRowItem);
     
                GridViewRelation relation = new GridViewRelation(gridView.MasterTemplate, template);
                relation.ChildColumnNames.Add("ParentID");
                relation.ParentColumnNames.Add("ID");
                gridView.Relations.Add(relation);
            }
     
            private void LoadData()
            {
                parentTable.Columns.Add("ID", typeof(int));
                parentTable.Columns.Add("ParentValue1", typeof(int));
                parentTable.Columns.Add("ParentValue2");
                parentTable.Columns.Add("ParentValue3", typeof(double));
                parentTable.Rows.Add(1, 100, "Value100", 100.1);
                parentTable.Rows.Add(2, 200, "Value200", 200.2);
                parentTable.Rows.Add(3, 300, "Value300", 300.3);
                parentTable.Rows.Add(4, 400, "Value400", 400.4);
                parentTable.Rows.Add(5, 500, "Value500", 500.3);
                gridView.DataSource = parentTable;
     
                childTable.Columns.Add("ID", typeof(int));
                childTable.Columns.Add("ParentID", typeof(int));
                childTable.Columns.Add("ChildValue1", typeof(int));
                childTable.Columns.Add("ChildValue2");
                childTable.Columns.Add("ChildValue3", typeof(double));
                childTable.Rows.Add(1, 1, 10, "Child100", 10.1);
                childTable.Rows.Add(2, 1, 20, "Child200", 20.2);
                childTable.Rows.Add(3, 2, 30, "Child300", 30.3);
                childTable.Rows.Add(4, 2, 40, "Child400", 40.4);
                childTable.Rows.Add(5, 2, 50, "Child500", 50.3);
                childTable.Rows.Add(6, 4, 60, "Child600", 60.3);
                childTable.Rows.Add(7, 5, 70, "Child700", 70.3);
                childTable.Rows.Add(8, 5, 80, "Child800", 80.3);
                childTable.Rows.Add(9, 5, 90, "Child900", 90.3);
                childTable.Rows.Add(10, 5, 100, "Child1000", 100.3);
     
                DataSet set = new DataSet();
                set.Tables.Add(parentTable);
                set.Tables.Add(childTable);
     
                set.Relations.Add("MyRelation", parentTable.Columns[0], childTable.Columns[1]);
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                this.expanded = SaveExpanded(this.gridView);
     
                gridView.DataSource = null;
                gridView.DataSource = parentTable;
     
                RestoreExpanded(this.expanded, this.gridView);
            }
     
            private void RestoreExpanded(HashSet<object> expanded, RadGridView rg)
            {
                foreach (var item in rg.Rows)
                {
                    if (expanded.Contains(((DataRowView)item.DataBoundItem)[0]))
                    {
                        item.IsExpanded = true;
                    }
                }
            }
     
            private HashSet<object> SaveExpanded(RadGridView rg)
            {
                HashSet<object> items = new HashSet<object>();
                foreach (var item in rg.Rows)
                {
                    if (item.IsExpanded)
                    {
                        items.Add(((DataRowView)item.DataBoundItem)[0]);
                    }
                }
     
                return items;
            }
        }
    }

    If you have other questions, do not hesitate to contact me again. 

    Kind regards,
    Julian Benkov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top