I'm trying to populate a label when i click on a node in a tree view but it only shows 1 value when i click on a other node it stays the same. this is the code i have
#region Read from database
private void loadlist()
{
cn.Open();
treeView1.Nodes.Clear();
cmd.CommandText = "SELECT * FROM Files ORDER BY FileName ASC";
try
{
dr = cmd.ExecuteReader();
while (dr.Read())
{
var paths = new List<string>
{
dr["FileName"].ToString(),
};
treeView1.PathSeparator = @"\";
PopulateTreeView(treeView1, paths, '\\');
//showMD5.Text = dr["MD5"].ToString();
//node.Nodes.Add(dr["MD5"].ToString()); //child node
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
dr.Close();
cn.Close();
}
i commented out 2 lines what i have tried. the first one just add's the MD5 values of the files under the current tree. i don't want/need that. the other line adds it as a child of that filename. i don't want that either.
i tried it with
treeView1_NodeMouseClick
and
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
cn.Open();
cmd.CommandText = "SELECT * FROM Files ORDER BY FileName ASC";
dr = cmd.ExecuteReader();
dr.Read();
showMD5.Text = dr["MD5"].ToString();
showSHA1.Text = dr["SHA1"].ToString();
dr.Close();
cn.Close();
}
but it only shows the values of the first row in the database.
Aucun commentaire:
Enregistrer un commentaire