How To Set TreeView Nodes Values Into DataGridView Rows Using C#
In this C# Tutorial we will see How To Get TreeView Nodes Data And Set It Into DataGridView Rows Using For Loop On Button Click Event In CSharp Programming Language And Visual Studio Editor.
Project Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class TreeView_To_DataGridView : Form
{
public TreeView_To_DataGridView()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for(int i = 0; i < treeView1.Nodes.Count; i++)
{
TreeNode node = treeView1.Nodes[i];
Object[] row = new Object[node.Nodes.Count];
for(int j = 0; j < node.Nodes.Count; j++)
{
row[j] = node.Nodes[j].Text;
}
dataGridView1.Rows.Add(row);
}
}
}
}
Post A Comment:
0 comments: