|
|
|
WinApp C# ระบุค่า checkbox ใน dataGridView ไม่ได้ครับ |
|
|
|
|
|
|
|
Code (C#)
void SetData()
{
this.toolStripStatusLabel1.Text = "Runing...";
if (string.IsNullOrEmpty(textBox1.Text)) return;
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add(new System.Data.DataColumn("Filename", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("Path", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("Size", typeof(double)));
dt.Columns.Add(new System.Data.DataColumn("Modified", typeof(DateTime)));
dt.Columns.Add(new System.Data.DataColumn("MD5", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("Select", typeof(bool)));
System.IO.Directory.GetFiles(this.textBox1.Text, "*.*", System.IO.SearchOption.AllDirectories).ToList<string>()
.ForEach(f =>
{
DataRow dr = dt.NewRow();
dr["Filename"] = System.IO.Path.GetFileName(f);
dr["Path"] = System.IO.Path.GetDirectoryName(f);
dr["Size"] = new System.IO.FileInfo(f).Length;
dr["Modified"] = new System.IO.FileInfo(f).LastAccessTime;
dr["MD5"] = GetMD5HashFromFile(f);
dr["Select"] = false;
dt.Rows.Add(dr);
this.toolStripStatusLabel1.Text = "Add File:" + f;
});
dataGridView1.Invoke(new Action(() =>
{
dataGridView1.DataSource = dt;
dataGridView1.Columns[0].Width = 250;
dataGridView1.Columns[1].Width = 450;
dataGridView1.Columns[4].Width = 250;
dataGridView1.Sort(dataGridView1.Columns[4], ListSortDirection.Ascending);
}));
this.toolStripStatusLabel1.Text = "Complete";
}
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
Color cl = Color.LightGoldenrodYellow;
string cri = "";
try
{
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
if (dataGridView1[4, i].Value.ToString() != cri)
{
cri = dataGridView1[4, i].Value.ToString();
cl = (cl != Color.LightGoldenrodYellow) ? Color.LightGoldenrodYellow : Color.LightCyan;
}
else
{
// dataGridView1[5, i].Value = true;
}
dataGridView1.Rows[i].DefaultCellStyle.BackColor = cl;
}
}
catch { }
}
Tag : .NET, Win (Windows App), C#, VS 2012 (.NET 4.x), VS 2013 (.NET 4.x)
|
|
|
|
|
|
Date :
2017-12-07 22:07:53 |
By :
lamaka.tor |
View :
1097 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้ได้แล้วโดยใช้
Code (C#)
dataGridView1.Rows.Add(.)
Code (C#)
void SetData()
{
this.toolStripStatusLabel1.Text = "Runing...";
if (string.IsNullOrEmpty(textBox1.Text)) return;
System.IO.Directory.GetFiles(this.textBox1.Text, "*.*", System.IO.SearchOption.AllDirectories).ToList<string>()
.ForEach(f =>
{
dataGridView1.Invoke(new Action(() =>
{
dataGridView1.Rows.Add(System.IO.Path.GetFileName(f),
System.IO.Path.GetDirectoryName(f),
new System.IO.FileInfo(f).Length,
new System.IO.FileInfo(f).LastAccessTime,
GetMD5HashFromFile(f),
false);
}));
this.toolStripStatusLabel1.Text = "Add File:" + f;
});
dataGridView1.Invoke(new Action(() =>
{
dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Ascending);
Color cl = Color.LightGoldenrodYellow;
string cri = "";
try
{
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
if (dataGridView1[4, i].Value.ToString() != cri)
{
cri = dataGridView1[4, i].Value.ToString();
cl = (cl != Color.LightGoldenrodYellow) ? Color.LightGoldenrodYellow : Color.LightCyan;
}
else
{
dataGridView1[5, i].Value = true;
}
dataGridView1.Rows[i].DefaultCellStyle.BackColor = cl;
}
}
catch { }
}));
this.toolStripStatusLabel1.Text = "Complete";
}
แทนการ ดึงมาจาก datatable ครับ
|
|
|
|
|
Date :
2017-12-08 00:19:53 |
By :
lamaka.tor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|