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

cannot add a new node dynamically(with DataSource)

3 Answers 216 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Takeuchi
Top achievements
Rank 1
Takeuchi asked on 27 Oct 2007, 05:02 PM

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?

private void Form1_Load(object sender, EventArgs e)  
{  
    DataSet dataSet1 = new DataSet();  
    tocTable = new DataTable("Toc");  
    tocTable.Columns.Add("Title"typeof(string));  
    tocTable.Columns.Add("Target"typeof(string));  
    tocTable.Columns.Add("id"typeof(int));  
    tocTable.Columns.Add("parentId"typeof(int));  
    dataSet1.Tables.Add(tocTable);  
 
    DataRow row = tocTable.NewRow();  
    row["Title"] = "Main Title";  
    row["Target"] = "d03.xml";  
    row["id"] = 1;  
    row["parentId"] = -1;  
    tocTable.Rows.Add(row);  
 
    row = tocTable.NewRow();  
    row["Title"] = "Child Title";  
    row["Target"] = "d0300000.xml";  
    row["id"] = 2;  
    row["parentId"] = 1;  
    tocTable.Rows.Add(row);  
 
    radTreeView1.DataMember = "Toc";  
    radTreeView1.DisplayMember = "Title";  
    radTreeView1.ValueMember = "id";  
    radTreeView1.ParentIDMember = "parentId";  
    radTreeView1.DataSource = dataSet1;              
 
}  
 
private void radButton1_Click(object sender, EventArgs e)  
{  
    DataRow row = tocTable.NewRow();  
    row["Title"] = "New node";  
    row["Target"] = "target";  
    row["id"] = 3;  
    row["parentId"] = 2;  
    tocTable.Rows.Add(row);  
      

Thank you in advance.

Keisaku

3 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 29 Oct 2007, 12:52 PM
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
0
Takeuchi
Top achievements
Rank 1
answered on 31 Oct 2007, 03:43 PM

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.

private DataView _dvUser;  
private BindingSource _bindCompany;  
 
public Form2()  
{  
    InitializeComponent();  
}  
 
private void Form2_Load(object sender, EventArgs e)  
{  
    DataSet dataSet1 = new DataSet();  
    DataTable dtCompany = new DataTable("COMPANY");  
    dtCompany.Columns.Add("ID"typeof(string));  
    dtCompany.Columns.Add("NAME"typeof(string));  
    dataSet1.Tables.Add(dtCompany);  
 
    DataRow row = dtCompany.NewRow();  
    row["ID"] = "C001";  
    row["NAME"] = "marumaru";  
    dtCompany.Rows.Add(row);  
 
    row = dtCompany.NewRow();  
    row["ID"] = "C002";  
    row["NAME"] = "kakukaku";  
    dtCompany.Rows.Add(row);  
 
    DataTable dtUser = new DataTable("USER");  
    dtUser.Columns.Add("ID"typeof(string));  
    dtUser.Columns.Add("COMPANY_ID"typeof(string));  
    dtUser.Columns.Add("NAME"typeof(string));  
    dataSet1.Tables.Add(dtUser);  
 
    _bindCompany = new BindingSource();  
    _bindCompany.DataSource = dtCompany;  
    _bindCompany.PositionChanged += new EventHandler(_bindCompany_PositionChanged);  
 
    row = dtUser.NewRow();  
    row["ID"] = "U001";  
    row["COMPANY_ID"] = "C001";  
    row["NAME"] = "suzuki";  
    dtUser.Rows.Add(row);  
 
    row = dtUser.NewRow();  
    row["ID"] = "U002";  
    row["COMPANY_ID"] = "C001";  
    row["NAME"] = "nakamura";  
    dtUser.Rows.Add(row);  
 
    radTreeView1.DataSource = _bindCompany;  
    _dvUser = new DataView(dtUser);  
    radGridView1.DataSource = _dvUser;  
}  
 
void _bindCompany_PositionChanged(object sender, EventArgs e)  
{  
    DataRowView drv = _bindCompany.Current as DataRowView;  
    if (drv != null)  
    {  
        _dvUser.RowFilter = "COMPANY_ID='" + drv.Row["ID"] + "'";  
        radGridView1.MasterGridViewInfo.UpdateFiltering();  
    }  

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

0
Julian Benkov
Telerik team
answered on 02 Nov 2007, 01:28 PM
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
Tags
Treeview
Asked by
Takeuchi
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Takeuchi
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or