Hi All,
I have 2 forms namely form1 and form2. i have datagridview in my form1 with fields checkbox,customer,journal and articleid.
by select the 1 or more cheque boxes and click add button the selected values of gridview(form1) should add to treeview (form2)
please help.
Thanks in advance.
Sarath
sarath phaniPosted Feb 18, 2009, 11:39 PM
private
void MainScreen_Load(object sender, EventArgs e){
string StrSql = "select distinct custid, customer from assignvalues where operator='" +GlobalVariables.uname + "'";
SqlCommand cmd = new SqlCommand(StrSql, con);
SqlDataAdapter da = new SqlDataAdapter();
con.Open();
da.SelectCommand = cmd;
da.Fill(dsCustomer);
con.Close();
string StrSqlJournal = "select distinct JournalId,journal,custid from assignvalues where operator='" + GlobalVariables.uname + "'";
SqlCommand cmdJournal = new SqlCommand(StrSqlJournal, con);
SqlDataAdapter daJournal = new SqlDataAdapter();
con.Open();
daJournal.SelectCommand = cmdJournal;
daJournal.Fill(dsJournals);
con.Close();
string StrSqlarticle = "select distinct JournalId,journal,custid,customer,article from assignvalues where operator='" + GlobalVariables.uname + "'";
SqlCommand cmdArticle = new SqlCommand(StrSqlarticle, con);
SqlDataAdapter daArticle = new SqlDataAdapter();
con.Open();
daArticle.SelectCommand = cmdArticle;
daArticle.Fill(dsArticle);
con.Close();
foreach (DataRow drCust in dsCustomer.Tables[0].Rows)
{
TreeNode tn = treeView1.Nodes.Add(Convert.ToString(drCust["Customer"]));
tn.Tag = Convert.ToString(drCust["CustID"]);
string CustID = drCust["CustID"].ToString();
foreach (DataRow drJou in dsJournals.Tables[0].Rows)
{
if (drJou["CustID"].ToString() == CustID)
{
TreeNode JouTn = tn.Nodes.Add(Convert.ToString(drJou["journal"]));
JouTn.Tag = Convert.ToString(drCust["CustID"]) +"-" + Convert.ToString(drJou["JournalId"]);
string JouID = drJou["JournalID"].ToString();
foreach (DataRow drArticleGet in dsArticle.Tables[0].Rows)
{
if (drArticleGet["JournalID"].ToString() == JouID && drArticleGet["CustID"].ToString() == CustID)
{
TreeNode ArticleTn = JouTn.Nodes.Add(drArticleGet["Article"].ToString());
ArticleTn.Tag = CustID + "-" + JouID + "-" + drArticleGet["Article"].ToString();
}
}
}
}
}
treeView1.ExpandAll();
}