如何复制我必须存储在节点中的列表以便稍后构建Treenode [英] How Do I Copy A List That I Have To Store In Node To Build Treenode Later
问题描述
我有从excel导入的数据列表,我想将它存储在节点中,例如
Pro_ID [0] duration [0] pressodesor [0]在一个节点我怎么能这样做任何人请帮助
我不知道从哪里开始......我有一个存储数据的列表。我得到了4个列表。
所有列表都链接为例如索引0处的列表是第一个链接的所有信息。
........................................... .......................................
这是我将数据存储在Excel中的代码列表
................. .................................................. ...............
private void button1_Click(object sender,EventArgs e)
{
试试
{
{
openFileDialog1.Filter =Excel Sheet(*。xlsx)| * .xlsx |所有文件(*。* )| *。*;
if(openFileDialog1.ShowDialog()== DialogResult.OK)
{
string FileName = openFileDialog1。文件名; //เอาทั้งชื่อและนามสกุลpath.GetFileName
// string path = // Application.StartupPath + @\ Myycel.xlsx; // Server.MapPath(File / MyExcel.xlsx);
string connstr =Provider = Microsoft.ACE.OLEDB.12.0; Data Source =+ FileName;
connstr + =;扩展属性= Excel 12.0;;
string strSQL =SELECT * FROM [Sheet1 $];
OleDbConnection con = new OleDbConnection(connstr);
con.Open();
OleDbCommand com;
com = new OleDbCommand(strSQL ,con);
OleDbDataReader odr;
com.Parameters.Clear();
odr = com.ExecuteReader();
DataTable dt = new DataTable();
if(odr.HasRows)
{
dt.Load(odr) ;
//dataGridView1.Columns[3].Visible = false;
//dataGridView1.Columns[2].Visible = false;
//dataGridView1.Columns [1] .Visible = false;
//dataGridView1.Columns[0].Visible = false;
dataGridView1.DataSource = dt;
}
else
{
dataGridView1.DataSource = null; ath.GetFileName
// string path = // Application .StartupPath + @\ Myycel.xlsx; /
}
odr.Close();
string FileName2 = openFileDialog1.FileName; Server.MapPath(File / MyExcel.xlsx);
string connstr2 =Provider = Microsoft.ACE.OLEDB.12.0; Data Source =+ FileName2;
connstr2 + =;扩展属性= Excel 12.0;;
string strSQL2 =SELECT * FROM [Sheet2 $];
OleDbConnection con2 = new OleDbConnection(connstr2);
con2.Open();
OleDbCommand com2;
com2 = new OleDbCommand(strSQL2,con2 );
OleDbDataReader odr2;
com2.Parameters.Clear();
odr2 = com2.ExecuteReader();
DataTable dt2 = new DataTable();
if(odr2.HasRows)
{
dt2.Load(odr2);
//dataGridView1.Columns[3].Visible = false;
//dataGridView1.Columns[2].Visible = false;
//dataGridView1.Columns [1] .Visible = false;
//dataGridView1.Columns[0].Visible = false;
dataGridView2.DataSource = dt2;
}
else
{
dataGridView2.DataSource = null;
}
odr2。关闭();
}
for(int X = 0; X< = dataGridView1.RowCount - 1; X ++)
{
Proj_name = Convert.ToString(dataGridView1.Rows [X] .Cells [0] .Value);
Proj_name_Values.Add(Convert.ToString(Proj_name));
}
for(int X = 0; X< = dataGridView1.RowCount - 1; X ++)
{
持续时间= Convert.ToInt32(dataGridView1.Rows [X]。单元格[1] .Value);
Duration_Values.Add(Convert.ToInt32(Duration));
}
for(int X = 0; X< = dataGridView1.RowCount - 1; X ++){
Predecessor = Convert .ToString(dataGridView1.Rows [X] .Cells [2] .Value);
String [] Word = Predecessor.Split('');
Predecessor_Number.Add(Convert.ToString(Word.Length));
Predecessor_Values.Add(Convert.ToString(Predecessor));
Predecessor_Value_FindLF.Add(Convert.ToString(Predecessor));
}
}
i got lists of data that import from excel and i want to store it in node for example
Pro_ID[0] duration[0] pressodesor[0] in a node how can i do it anyone please help
well i didn't know where to start ...... i got an lists that store data. i got like 4 lists.
all list is linked for example list at index 0 are all the information to the first link.
..................................................................................
here is my code to store the data in excel to list
..................................................................................
private void button1_Click(object sender, EventArgs e)
{
try
{
{
openFileDialog1.Filter = "Excel Sheet(*.xlsx)|*.xlsx|All Files(*.*)|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string FileName = openFileDialog1.FileName; // เอาทั้งชื่อและนามสกุล path.GetFileName
//string path = // Application.StartupPath + @"\MyExcel.xlsx"; // Server.MapPath("File/MyExcel.xlsx");
string connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName;
connstr += ";Extended Properties=Excel 12.0;";
string strSQL = "SELECT * FROM [Sheet1$]";
OleDbConnection con = new OleDbConnection(connstr);
con.Open();
OleDbCommand com;
com = new OleDbCommand(strSQL, con);
OleDbDataReader odr;
com.Parameters.Clear();
odr = com.ExecuteReader();
DataTable dt = new DataTable();
if (odr.HasRows)
{
dt.Load(odr);
//dataGridView1.Columns[3].Visible = false;
//dataGridView1.Columns[2].Visible = false;
//dataGridView1.Columns[1].Visible = false;
//dataGridView1.Columns[0].Visible = false;
dataGridView1.DataSource = dt;
}
else
{
dataGridView1.DataSource = null;ath.GetFileName
//string path = // Application.StartupPath + @"\MyExcel.xlsx"; /
}
odr.Close();
string FileName2 = openFileDialog1.FileName; Server.MapPath("File/MyExcel.xlsx");
string connstr2 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName2;
connstr2 += ";Extended Properties=Excel 12.0;";
string strSQL2 = "SELECT * FROM [Sheet2$]";
OleDbConnection con2 = new OleDbConnection(connstr2);
con2.Open();
OleDbCommand com2;
com2 = new OleDbCommand(strSQL2, con2);
OleDbDataReader odr2;
com2.Parameters.Clear();
odr2 = com2.ExecuteReader();
DataTable dt2 = new DataTable();
if (odr2.HasRows)
{
dt2.Load(odr2);
//dataGridView1.Columns[3].Visible = false;
//dataGridView1.Columns[2].Visible = false;
//dataGridView1.Columns[1].Visible = false;
//dataGridView1.Columns[0].Visible = false;
dataGridView2.DataSource = dt2;
}
else
{
dataGridView2.DataSource = null;
}
odr2.Close();
}
for (int X = 0; X <= dataGridView1.RowCount - 1; X++)
{
Proj_name = Convert.ToString(dataGridView1.Rows[X].Cells[0].Value);
Proj_name_Values.Add(Convert.ToString(Proj_name));
}
for (int X = 0; X <= dataGridView1.RowCount - 1; X++)
{
Duration = Convert.ToInt32(dataGridView1.Rows[X].Cells[1].Value);
Duration_Values.Add(Convert.ToInt32(Duration));
}
for (int X = 0; X <= dataGridView1.RowCount - 1; X++) {
Predecessor = Convert.ToString(dataGridView1.Rows[X].Cells[2].Value);
String[] Word = Predecessor.Split(' ');
Predecessor_Number.Add(Convert.ToString(Word.Length));
Predecessor_Values.Add(Convert.ToString(Predecessor));
Predecessor_Value_FindLF.Add(Convert.ToString(Predecessor));
}
}
推荐答案
;
OleDbConnection con = new OleDbConnection(connstr);
con.Open();
OleDbCommand com; < br $>
com = new OleDbCommand(strSQL,con);
OleDbDataReader odr;
com.Parameters.Clear();
odr = com.ExecuteReader();
DataTable dt = new DataTable();
if(odr.HasRows)
{
dt.Load(odr);
//dataGridView1.Columns[3].Visible = false;
//dataGridView1.Columns [2] .Visible = false;
//dataGridView1.Columns [1] .Visible = false;
//dataGridView1.Columns[0].Visible = false;
dataGridView1.DataSource = dt;
}
else
{
dataGridView1.DataSource = null; ath.GetFileName
// string path = // Application.StartupPath + @\ Myycel.xlsx; /
}
odr.Close();
string FileName2 = openFileDialog1.FileName; Server.MapPath(File / MyExcel.xlsx);
string connstr2 =Provider = Microsoft.ACE.OLEDB.12.0; Data Source =+ FileName2;
connstr2 + =;扩展属性= Excel 12.0;;
string strSQL2 =SELECT * FROM [Sheet2
";
OleDbConnection con = new OleDbConnection(connstr);
con.Open();
OleDbCommand com;
com = new OleDbCommand(strSQL, con);
OleDbDataReader odr;
com.Parameters.Clear();
odr = com.ExecuteReader();
DataTable dt = new DataTable();
if (odr.HasRows)
{
dt.Load(odr);
//dataGridView1.Columns[3].Visible = false;
//dataGridView1.Columns[2].Visible = false;
//dataGridView1.Columns[1].Visible = false;
//dataGridView1.Columns[0].Visible = false;
dataGridView1.DataSource = dt;
}
else
{
dataGridView1.DataSource = null;ath.GetFileName
//string path = // Application.StartupPath + @"\MyExcel.xlsx"; /
}
odr.Close();
string FileName2 = openFileDialog1.FileName; Server.MapPath("File/MyExcel.xlsx");
string connstr2 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName2;
connstr2 += ";Extended Properties=Excel 12.0;";
string strSQL2 = "SELECT * FROM [Sheet2
;
OleDbConnection con2 = new OleDbConnection(connstr2);
con2.Open();
OleDbCommand com2;
com2 = new OleDbCommand(strSQL2,con2);
OleDbDataReader odr2;
com2.Parameters.Clear();
odr2 = com2。 ExecuteReader();
DataTable dt2 = new DataTable();
if(odr2.HasRows)
{
dt 2.Load(odr2);
//dataGridView1.Columns[3].Visible = false;
//dataGridView1.Columns [2] .Visible = false;
//dataGridView1.Columns[1].Visible = false;
//dataGridView1.Columns[0].Visible = false;
dataGridView2 .DataSource = dt2;
}
else
{
dataGridView2.DataSource = null;
}
odr2.Close();
}
for(int X = 0; X< = dataGridView1.RowCount - 1; X ++)
{
Proj_name = Convert.ToString(dataGridView1.Rows [X] .Cells [0] .Value);
Proj_name_Values.Add(Convert.ToString(Proj_name));
}
for(int X = 0; X< = dataGridView1.RowCount - 1; X ++)
{
持续时间= Convert.ToInt32(dataGridView1.Rows [X]。单元格[1] .Value);
Duration_Values.Add(Convert.ToInt32(Duration));
}
for(int X = 0; X< = dataGridView1.RowCount - 1; X ++){
Predecessor = Convert .ToString(dataGridView1.Rows [X] .Cells [2] .Value);
String [] Word = Predecessor.Split('');
Predecessor_Number.Add(Convert.ToString(Word.Length));
Predecessor_Values.Add(Convert.ToString(Predecessor));
Predecessor_Value_FindLF.Add(Convert.ToString(Predecessor));
}
}
";
OleDbConnection con2 = new OleDbConnection(connstr2);
con2.Open();
OleDbCommand com2;
com2 = new OleDbCommand(strSQL2, con2);
OleDbDataReader odr2;
com2.Parameters.Clear();
odr2 = com2.ExecuteReader();
DataTable dt2 = new DataTable();
if (odr2.HasRows)
{
dt2.Load(odr2);
//dataGridView1.Columns[3].Visible = false;
//dataGridView1.Columns[2].Visible = false;
//dataGridView1.Columns[1].Visible = false;
//dataGridView1.Columns[0].Visible = false;
dataGridView2.DataSource = dt2;
}
else
{
dataGridView2.DataSource = null;
}
odr2.Close();
}
for (int X = 0; X <= dataGridView1.RowCount - 1; X++)
{
Proj_name = Convert.ToString(dataGridView1.Rows[X].Cells[0].Value);
Proj_name_Values.Add(Convert.ToString(Proj_name));
}
for (int X = 0; X <= dataGridView1.RowCount - 1; X++)
{
Duration = Convert.ToInt32(dataGridView1.Rows[X].Cells[1].Value);
Duration_Values.Add(Convert.ToInt32(Duration));
}
for (int X = 0; X <= dataGridView1.RowCount - 1; X++) {
Predecessor = Convert.ToString(dataGridView1.Rows[X].Cells[2].Value);
String[] Word = Predecessor.Split(' ');
Predecessor_Number.Add(Convert.ToString(Word.Length));
Predecessor_Values.Add(Convert.ToString(Predecessor));
Predecessor_Value_FindLF.Add(Convert.ToString(Predecessor));
}
}
这篇关于如何复制我必须存储在节点中的列表以便稍后构建Treenode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!