I have a TreeView and on a separate panel 3 checkboxes. The Treeview data is being pulled from a database,this database has two tables Product and Model inside the Model table there are 3 columns - twoDoor, threeDoor and fiveDoor. My TreeView looks like this;
CAR(PRODUCT) ->FORD(MODEL) ->BMW(MODEL) ->VW(MODEL) On a separate panel there are 3 checkboxes;
- Two Door
- Three Door
- Five Door
The state of these checkboxes are already defined in the Model db. How can i display their state against whatever child Node(Model) is picked in the TreeView?
My Code:
private void Form1_Options_Load(object sender, EventArgs e) { String connectionString; connectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString; conn = new SqlConnection(connectionString); String Sequel = "SELECT id,ProductName,ModelType FROM Product"; SqlDataAdapter da = new SqlDataAdapter(Sequel, conn); DataTable dt = new DataTable(); conn.Open(); da.Fill(dt); foreach (DataRow dr in dt.Rows) { parentNode = treeView1.Nodes.Add(dr["ProductName"].ToString()); //treeView1.Nodes.Add(dr["ModelType"].ToString()); PopulateTreeView(Convert.ToInt32(dr["Id"].ToString()), parentNode); } } public void PopulateTreeView(int parentId, TreeNode parentNode) { String Seqchildc = "Select * From Model WHERE ProductId = "+ parentId + ""; SqlDataAdapter dachildmnuc = new SqlDataAdapter(Seqchildc, conn); DataTable dtchildc = new DataTable(); dachildmnuc.Fill(dtchildc); TreeNode childNode; foreach (DataRow dr in dtchildc.Rows) { if (parentNode == null) childNode = treeView1.Nodes.Add(dr["ModelName"].ToString()); //childNode.Nodes.Add(dr["ModelType"].ToString()); else childNode = parentNode.Nodes.Add(dr["ModelName"].ToString()); //PopulateTreeView(Convert.ToInt32(dr["Id"].ToString()), childNode); } treeView1.ExpandAll(); //Connect(); }
TreeNodeandProduct/Modelclasses?Tag?