02-控件操作/添加内容到Treeview/AddContentToTreeView/Form1.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace AddContentToTreeView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//声明本程序需要的变量
public static string[,] recordInfo;
private void Form1_Load(object sender, EventArgs e)
{
#region 在DataGridView及TreeView中显示数据
string connString = "server=.;database=pubs;integrated security=sspi";
SqlConnection conn = new SqlConnection(connString);
conn.Open();
string selectString = "select au_id as 用户编号,au_lname as 用户名,phone as 联系电话 from authors";
SqlDataAdapter Adapter = new SqlDataAdapter(selectString, conn);
DataSet dataset = new DataSet();
Adapter.Fill(dataset, "UserInfo");
dataGridView1.DataSource = dataset.Tables["UserInfo"].DefaultView;
TreeNode treeNode = new TreeNode("用户信息", 0, 0);
treeView1.Nodes.Add(treeNode);
#endregion
}
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
if (dataGridView1.SelectedCells.Count != 0)
{
//定义一个二维数组,数组中的每一行代表DataGridView中的一条记录
recordInfo = new string[dataGridView1.Rows.Count, dataGridView1.Columns.Count];
//当按下鼠标左键时,首先获取选定行,记录每一行对应的信息
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Selected)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
recordInfo[i, j] = dataGridView1.Rows[i].Cells[j].Value.ToString();
}
}
}
}
}
private void treeView1_MouseEnter(object sender, EventArgs e)
后面还有 46 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
