|
 |
|
checkbox ใน dataview อยากให้ติ๊กถูกจาก ค่า ustatus ที่ดึงจาก sql ที่เก็บค่าเป็น 1 ถ้าเป็น 0 แล้ว ไม่ต้องติ๊ก พยายามทำแล้วแต่ไม่แสดงให้ค่ะ ไม่รู้ว่า รำโค๊ดผิดหรือป่าว รบกวนทุกท่านดูให้หน่อยค่ะ |
|
 |
|
|
 |
 |
|
รบกวนทุกท่านช่วยดูให้หน่อยค่ะ
อยากให้ checkbox ใน dataview แสดงติ๊กถูก ค่าที่เปน 1 ถ้าเป็น 0 ไม่ต้อง ติ๊กถูก
ซึ่งค่าที่เป็น 1 เป้น 0 นั้นดึงข้อมูลมาจาก sql ค่ะ

Code (C#)
private void bindData()
{
cn.Open();
string Sql = "SELECT USERID,USERNAME,REALNAME,DEPART,USTATUS FROM DAILY_LOG_USER";
cmd = new SqlCommand(Sql, cn);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.Columns["ustatus"].Visible = false;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
try
{
if (row.Cells["ustatus"].Value.ToString() == "1" && row.Cells["ustatus"].Value.ToString() == "true")
{
DataGridViewCheckBoxCell ckBox = (DataGridViewCheckBoxCell)row.Cells["ustatus"];
ckBox.Value = true;
}
else if (row.Cells[4].Value.ToString() == "false")
{
DataGridViewCheckBoxCell ckBox = (DataGridViewCheckBoxCell)row.Cells["ustatus"];
ckBox.Value = false;
}
}
catch
{
}
}
}
Code (C#)
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
if (globalcheckboxcolumn == 0)
{
if (dataGridView1.Rows.Count != 0)
{
DataGridViewCheckBoxColumn chSelect = new DataGridViewCheckBoxColumn();
{
chSelect.HeaderText = "ใช้ระบบ";
chSelect.Name = "chselect";
chSelect.Selected = false;
}
dataGridView1.Columns.Insert(4, chSelect);
}
}
Tag : .NET, Win (Windows App), C#, Windows

|
ประวัติการแก้ไข 2013-05-26 21:10:49 2013-05-26 21:12:48 2013-05-26 21:14:04
|
 |
 |
 |
 |
Date :
2013-05-26 21:03:28 |
By :
K927 |
View :
1064 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วค่ะ รำโค๊ดผิดจิงๆ ด้วย
ที่แก้ไขแล้ว
Code (C#)
private void bindData()
{
cn.Open();
string Sql = "SELECT USERID,USERNAME,REALNAME,DEPART,USTATUS FROM DAILY_LOG_USER";
cmd = new SqlCommand(Sql, cn);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.Columns["USTATUS"].Visible = false;
dataGridView1.Columns[5].Visible = false;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
try
{
if (row.Cells["ustatus"].Value.ToString() == "1")
{
DataGridViewCheckBoxCell ckBox = (DataGridViewCheckBoxCell)row.Cells["chselect"];
ckBox.Value = true;
}
else if (row.Cells["ustatus"].Value.ToString() == "0" && row.Cells["ustatus"].Value.ToString() == null)
{
DataGridViewCheckBoxCell ckBox = (DataGridViewCheckBoxCell)row.Cells["chselect"];
ckBox.Value = false;
}
}
catch
{
}
}
}
Code (C#)
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
if (globalcheckboxcolumn == 0)
{
if (dataGridView1.Rows.Count != 0)
{
DataGridViewCheckBoxColumn chSelect = new DataGridViewCheckBoxColumn();
{
chSelect.HeaderText = "ใช้ระบบ";
chSelect.Name = "chselect";
chSelect.Selected = false;
}
dataGridView1.Columns.Insert(5, chSelect);
}
}
}
จุดที่ก็มี
Code (C#)
DataGridViewCheckBoxCell ckBox = (DataGridViewCheckBoxCell)row.Cells["chselect"];
Code (C#)
DataGridViewCheckBoxCell ckBox = (DataGridViewCheckBoxCell)row.Cells["chselect"];
และ
Code (C#)
dataGridView1.Columns.Insert(5, chSelect);
เส้นผมบังตา แถ้ๆ  
|
 |
 |
 |
 |
Date :
2013-05-26 22:26:46 |
By :
K927 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2013-05-27 06:12:29 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|