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

Setting select nodes as checked server side

3 Answers 81 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bruce St.Clair
Top achievements
Rank 2
Bruce St.Clair asked on 17 Sep 2008, 03:22 PM
When I databind serverside I want to set certain nodes as checked.  I poured through the forums and help files but cant find anything close to what I am doing.

Code Snippet:

try

{

DataSet dsp = new DataSet();

DB.m_da.SetRead("SELECT 'All Providers' AS [Name], '0' AS [ID], null as tree union SELECT [FName] + ' ' + [LName] AS [Name], [ID],0 as [Tree] FROM Provider WHERE [Inactive] = 0 ORDER BY 1", 1);

DB.m_da.Run(ref dsp);

RadTreeView1.DataSource = dsp;

RadTreeView1.DataFieldID =

"ID";

RadTreeView1.DataValueField =

"ID";

RadTreeView1.DataTextField =

"Name";

RadTreeView1.DataFieldParentID =

"Tree";

RadTreeView1.DataBind();

DataSet ds = new DataSet();

DB.m_da.SetRead("Select VID from AppointmentUserSetting where onoff = 1", 1);

DB.m_da.Run(ref ds);

foreach (DataRow row in ds.Tables[0].Rows)

{

// This is where I want to set the node to checked

// node.checked = true;

}

RadTreeView1.ExpandAllNodes();

RadTreeView1.MultipleSelect =

true;

RadTreeView1.CheckBoxes =

true;

Label1.Text =

"";

 

 

}

3 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 19 Sep 2008, 06:38 AM
Hi Bruce St.Clair,

You should use the NodeDataBound event to set the Checked property of the nodes created during databinding.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Bruce St.Clair
Top achievements
Rank 2
answered on 19 Sep 2008, 01:22 PM
Well I came up with a different approach and thought I should share it incase anybody else runs into the same problem.  My data is for the tree comes from 2 completely differnet areas of my database.  1 area is to fill the tree and the checked box selection come from a user preferences ara.  So below you will find my approach to fit my needs with comments.  Hope this help anybody else they may need this approach.

Code snippet.

RadTreeView1.Nodes.Clear();

//Set our crud layer

DataAccess.

DA dt = new DA("Connection string");

DB.m_da = dt;

try

{

//Get all the data to fill the tree without the check boxes filled

DataSet dsp = new DataSet();

DB.m_da.SetRead(

"SELECT 'All Providers' AS [Name], '0' AS [ID], null as tree union SELECT [FName] + ' ' + [LName] AS [Name], [ID],0 as [Tree] FROM Provider WHERE [Inactive] = 0 ORDER BY 1", 1);

DB.m_da.Run(

ref dsp);

 

//Databind the tree to show all doctors

RadTreeView1.DataSource = dsp;

RadTreeView1.DataFieldID =

"ID";

RadTreeView1.DataValueField =

"ID";

RadTreeView1.DataTextField =

"Name";

RadTreeView1.DataFieldParentID =

"Tree";

RadTreeView1.DataBind();

//Now get the users previous selections of what doctor they have selected to view in the calendar

DataSet ds = new DataSet();

DB.m_da.SetRead(

"Select VID from AppointmentUserSetting where onoff = 1 and UID = 1 and IDType = 'D'", 1);

DB.m_da.Run(

ref ds);

// Now apply the check boxes to match what the user selection are if 0 then select root parent

// If not root then fill in the correct check boxes

foreach (DataRow row in ds.Tables[0].Rows)

{

if (row.ItemArray.GetValue(0).ToString() == "0")

{

RadTreeNode rtn =

this.RadTreeView1.FindNodeByValue(row.ItemArray.GetValue(0).ToString());

rtn.Checked =

true;

break;

}

else

{

RadTreeNode rtn =

this.RadTreeView1.FindNodeByValue(row.ItemArray.GetValue(0).ToString());

rtn.Checked =

true;

}

}

//now set the tree to my liking

RadTreeView1.ExpandAllNodes();

RadTreeView1.MultipleSelect =

true;

RadTreeView1.CheckBoxes =

true;

}

0
Bruce St.Clair
Top achievements
Rank 2
answered on 19 Sep 2008, 01:22 PM
Well I came up with a different approach and thought I should share it incase anybody else runs into the same problem.  My data is for the tree comes from 2 completely differnet areas of my database.  1 area is to fill the tree and the checked box selection come from a user preferences ara.  So below you will find my approach to fit my needs with comments.  Hope this help anybody else they may need this approach.

Code snippet.

RadTreeView1.Nodes.Clear();

//Set our crud layer

DataAccess.

DA dt = new DA("Connection string");

DB.m_da = dt;

try

{

//Get all the data to fill the tree without the check boxes filled

DataSet dsp = new DataSet();

DB.m_da.SetRead(

"SELECT 'All Providers' AS [Name], '0' AS [ID], null as tree union SELECT [FName] + ' ' + [LName] AS [Name], [ID],0 as [Tree] FROM Provider WHERE [Inactive] = 0 ORDER BY 1", 1);

DB.m_da.Run(

ref dsp);

 

//Databind the tree to show all doctors

RadTreeView1.DataSource = dsp;

RadTreeView1.DataFieldID =

"ID";

RadTreeView1.DataValueField =

"ID";

RadTreeView1.DataTextField =

"Name";

RadTreeView1.DataFieldParentID =

"Tree";

RadTreeView1.DataBind();

//Now get the users previous selections of what doctor they have selected to view in the calendar

DataSet ds = new DataSet();

DB.m_da.SetRead(

"Select VID from AppointmentUserSetting where onoff = 1 and UID = 1 and IDType = 'D'", 1);

DB.m_da.Run(

ref ds);

// Now apply the check boxes to match what the user selection are if 0 then select root parent

// If not root then fill in the correct check boxes

foreach (DataRow row in ds.Tables[0].Rows)

{

if (row.ItemArray.GetValue(0).ToString() == "0")

{

RadTreeNode rtn =

this.RadTreeView1.FindNodeByValue(row.ItemArray.GetValue(0).ToString());

rtn.Checked =

true;

break;

}

else

{

RadTreeNode rtn =

this.RadTreeView1.FindNodeByValue(row.ItemArray.GetValue(0).ToString());

rtn.Checked =

true;

}

}

//now set the tree to my liking

RadTreeView1.ExpandAllNodes();

RadTreeView1.MultipleSelect =

true;

RadTreeView1.CheckBoxes =

true;

}

Tags
TreeView
Asked by
Bruce St.Clair
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Bruce St.Clair
Top achievements
Rank 2
Share this question
or