i have two form, in form1, i am having a datagrid view and its datasource is a database, now what i am trying to achieve is, i want selected rows's data of the datagridview on the other form form2 's treeview nodes.
i have tried this in form1
List<globals> DatagridViewDataObject = new List<globals>();
foreach (DataGridViewRow item in DataGridViewPersonalDetails.Rows)
{
if (Convert.ToBoolean(item.Cells[0].Value))
{
DatagridViewDataObject.Add(new Globals
{
Serial_Number = item.Cells[0].Value.ToString(),
Name = item.Cells[1].Value.ToString(),
Address = item.Cells[2].Value.ToString(),
City = item.Cells[3].Value.ToString(),
Zip_Code = item.Cells[4].Value.ToString(),
});
}
}
LiveWin LiveWinObject = new LiveWin();
LiveWinObject.Values = DatagridViewDataObject;
LiveWinObject.Show();
What I have tried:
this is my method to get data into tree view and i haved called the method into the form2 load event
public void AddDataToGridView(List<Globals> val)
{
if (val != null)
{
for (int i = 0; i < val.Count; i++)
{
int RowIndex = i + 1;
TreeNode NodeOfTree = new TreeNode("Row_" + RowIndex);
for (int j = 0; j < val.Count; j++)
{
treeView1.Nodes[i].Nodes[j].Nodes.Add(NodeOfTree);
}
treeView1.Nodes.Add(NodeOfTree);
}
}
}