Click here to Skip to main content
15,885,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
                }
            }
        }
Posted
Updated 2-Mar-22 22:58pm

1 solution

Exactly how depends on the "relationship" between the two forms.
Have a look at these, one of them will fit your circumstances.
The form that creates an instance of another:
C#
MyForm mf = new MyForm();
mf.Show();
Is the "parent", the other form is the "child".
(This doesn't imply any formal MDI relationship)

Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900