cannot add a new node dynamically(with DataSource)

4 posts, 0 answers
  1. Takeuchi
    Takeuchi avatar
    2 posts
    Member since:
    Oct 2007

    Posted 27 Oct 2007 Link to this post

    Hi, I have a problem with  adding a child node dynamically.
    I'm using the RadControls for WinForms Q2 2007 SP1.

    I wrote a following code: 

    1. Show RadTreeView with two nodes.
    2. When button clicked, add one node to RadTreeView.

    But 2. is not working(RadTreeView has still two nodes).
    How do I add a new node to RadTreeView?

    1 private void Form1_Load(object sender, EventArgs e)  
    2 {  
    3     DataSet dataSet1 = new DataSet();  
    4     tocTable = new DataTable("Toc");  
    5     tocTable.Columns.Add("Title"typeof(string));  
    6     tocTable.Columns.Add("Target"typeof(string));  
    7     tocTable.Columns.Add("id"typeof(int));  
    8     tocTable.Columns.Add("parentId"typeof(int));  
    9     dataSet1.Tables.Add(tocTable);  
    10  
    11     DataRow row = tocTable.NewRow();  
    12     row["Title"] = "Main Title";  
    13     row["Target"] = "d03.xml";  
    14     row["id"] = 1;  
    15     row["parentId"] = -1;  
    16     tocTable.Rows.Add(row);  
    17  
    18     row = tocTable.NewRow();  
    19     row["Title"] = "Child Title";  
    20     row["Target"] = "d0300000.xml";  
    21     row["id"] = 2;  
    22     row["parentId"] = 1;  
    23     tocTable.Rows.Add(row);  
    24  
    25     radTreeView1.DataMember = "Toc";  
    26     radTreeView1.DisplayMember = "Title";  
    27     radTreeView1.ValueMember = "id";  
    28     radTreeView1.ParentIDMember = "parentId";  
    29     radTreeView1.DataSource = dataSet1;              
    30  
    31 }  
    32  
    33 private void radButton1_Click(object sender, EventArgs e)  
    34 {  
    35     DataRow row = tocTable.NewRow();  
    36     row["Title"] = "New node";  
    37     row["Target"] = "target";  
    38     row["id"] = 3;  
    39     row["parentId"] = 2;  
    40     tocTable.Rows.Add(row);  
    41       
    42

    Thank you in advance.

    Keisaku
  2. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 29 Oct 2007 Link to this post

    Hello Takeuchi,

    Indeed, there is an issue with the RadTreeView data binding that prevents you from adding child nodes in this way.
    You can expect this functionality to be available in the upcoming 2007 Q2 SP2 release.

    Thank you for contacting us. Please write us again, in case you have any additional questions.

    Sincerely yours,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Takeuchi
    Takeuchi avatar
    2 posts
    Member since:
    Oct 2007

    Posted 31 Oct 2007 Link to this post

    Hello Jordan,

    Thank you for your answer.
    I'm looking forward to SP2 release.

    Now I have an additional question.
    I think it might be related in a previous question.
    Or it might be related in RadGridView.

    I wrote a following code:

    There are two tables:
    COMPANY_TABLE and USER_TABLE.

    COMPANY_TABLE : USER_TABLE = 1 : n.

    I placed RadTreeView and RadGridView in Form.
    RadTreeView is to show companys in COMPANY_TABLE,
    and RadGridView is to show users in USER_TABLE.
    Select one company in RadTreeView,
    then display users who belong to the company in RadGridView.
    I used DataView's RowFilter.

    1 private DataView _dvUser;  
    2 private BindingSource _bindCompany;  
    3  
    4 public Form2()  
    5 {  
    6     InitializeComponent();  
    7 }  
    8  
    9 private void Form2_Load(object sender, EventArgs e)  
    10 {  
    11     DataSet dataSet1 = new DataSet();  
    12     DataTable dtCompany = new DataTable("COMPANY");  
    13     dtCompany.Columns.Add("ID"typeof(string));  
    14     dtCompany.Columns.Add("NAME"typeof(string));  
    15     dataSet1.Tables.Add(dtCompany);  
    16  
    17     DataRow row = dtCompany.NewRow();  
    18     row["ID"] = "C001";  
    19     row["NAME"] = "marumaru";  
    20     dtCompany.Rows.Add(row);  
    21  
    22     row = dtCompany.NewRow();  
    23     row["ID"] = "C002";  
    24     row["NAME"] = "kakukaku";  
    25     dtCompany.Rows.Add(row);  
    26  
    27     DataTable dtUser = new DataTable("USER");  
    28     dtUser.Columns.Add("ID"typeof(string));  
    29     dtUser.Columns.Add("COMPANY_ID"typeof(string));  
    30     dtUser.Columns.Add("NAME"typeof(string));  
    31     dataSet1.Tables.Add(dtUser);  
    32  
    33     _bindCompany = new BindingSource();  
    34     _bindCompany.DataSource = dtCompany;  
    35     _bindCompany.PositionChanged += new EventHandler(_bindCompany_PositionChanged);  
    36  
    37     row = dtUser.NewRow();  
    38     row["ID"] = "U001";  
    39     row["COMPANY_ID"] = "C001";  
    40     row["NAME"] = "suzuki";  
    41     dtUser.Rows.Add(row);  
    42  
    43     row = dtUser.NewRow();  
    44     row["ID"] = "U002";  
    45     row["COMPANY_ID"] = "C001";  
    46     row["NAME"] = "nakamura";  
    47     dtUser.Rows.Add(row);  
    48  
    49     radTreeView1.DataSource = _bindCompany;  
    50     _dvUser = new DataView(dtUser);  
    51     radGridView1.DataSource = _dvUser;  
    52 }  
    53  
    54 void _bindCompany_PositionChanged(object sender, EventArgs e)  
    55 {  
    56     DataRowView drv = _bindCompany.Current as DataRowView;  
    57     if (drv != null)  
    58     {  
    59         _dvUser.RowFilter = "COMPANY_ID='" + drv.Row["ID"] + "'";  
    60         radGridView1.MasterGridViewInfo.UpdateFiltering();  
    61     }  
    62

    1.Select C001 in RadTreeView, then display two users in RadGridView.
    2.Select C002 in RadTreeView, then display no user in RadGridView.
    3.Select C002 in RadTreeView, add one user in RadGridView.
    4.Select C001 in RadTreeView, then display only one user in RadGridView.
     
    In case of 4, there have to be two users who displayed in 1. 

    I wrote a same code using Microsoft's DataGridView,
    but the same problem didn't occur.

    Yours faithfully,

    Keisaku

  5. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 02 Nov 2007 Link to this post

    Hello Takeuchi,

    We have found some issues related to refreshing of RadGridView after adding a new record and applying a row filter to the bound object (modifying the filter of a bound DataTable, for example). The fix will available for our next Q3 release.

    Filtering in this case will work fine if you use the current RadGridView API:

    (radGridView1.MasterGridViewTemplate.Columns["COMPANY_ID"as GridViewDataColumn).Filter.StringValue = "C001";  
    (radGridView1.MasterGridViewTemplate.Columns["COMPANY_ID"as GridViewDataColumn).Filter.Function = GridKnownFunction.EqualTo;  
    radGridView1.MasterGridViewInfo.UpdateFiltering(); 

    I hope this helps. If you have any additional questions, please contact us again.

    Sincerely yours,
    Julian Benkov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top