Datagridview复选框值以编程方式设置为true,但在视觉上未检查。 [英] Datagridview checkbox value set true programatically but visually not checked.
问题描述
亲爱的朋友
帮助我!
我在Windows窗体中有五个datagridview.each datagridview包含复选框列的第一列。我务实地匹配某些标准,并为复选框列设置值为true。当我调试程序时,我看到代码命中... r2.cells [0] .value = true ..但在视觉上没有改变。只有第一个datagridview复选框vaue在视觉上保持不变。
请帮我解决我的错误。
代码如下..
Dear Friend
Help me!
I have five datagridview in a windows form.each datagridview contains first column of checkbox column.I match certain criteria pragmatically and set value for checkbox column true.When i debug program i see that code hit ...r2.cells[0].value =true ..but visually not changed.only first datagridview checkbox vaue change visually remain unchanged.
Please help me what i am doing wrong.
Code is as below..
#region Dhulai Labour(Only dgvlgodawn is checked visually too)
DataTable dt2 = Mst.LabourWork(1, dt.Rows[0]["lot_Nos"].ToString());
if (dt2.Rows.Count > 0)
{
for (int i = 0; i <= dt2.Rows.Count - 1; i++)
{
foreach (DataGridViewRow r in dgvLGodawn.Rows)
{
if (r.Cells[1].Value.ToString() == dt2.Rows[i]["labourid"].ToString())
{
r.Cells[0].Value = true;
r.Cells[3].Value = decimal.Parse(dt2.Rows[i]["wagesamount"].ToString());
}
}
}
}
#endregion
#region chakai Labour
DataTable dt3 = Mst.LabourWork(2, dt.Rows[0]["lot_Nos"].ToString());
if (dt3.Rows.Count > 0)
{
for (int j= 0; j<= dt3.Rows.Count - 1; j++)
{
for (int i = 1; i <= dgvLchhakna.Rows.Count - 1; i++)
{
if (dgvLchhakna.Rows[i].Cells[1].Value.ToString() == dt3.Rows[j]["labourid"].ToString())
{
dgvLchhakna.Rows[i].Cells[0].Value = true;
dgvLchhakna.Rows[i].Cells[3].Value = decimal.Parse(dt3.Rows[j]["wagesamount"].ToString());
}
}
}
}
#endregion
#region Halar Labour
DataTable dt4 = Mst.LabourWork(3, dt.Rows[0]["lot_Nos"].ToString());
if (dt4.Rows.Count > 0)
{
for (int i = 0; i <= dt4.Rows.Count - 1; i++)
{
foreach (DataGridViewRow r2 in dgvLHalar.Rows)
{
if (r2.Cells[1].Value.ToString() == dt4.Rows[i]["labourid"].ToString())
{
r2.Cells[0].Value = true;
r2.Cells[3].Value = decimal.Parse(dt4.Rows[i]["wagesamount"].ToString());
}
}
}
}
#endregion
#region Kutai Labour
DataTable dt5 = Mst.LabourWork(4, dt.Rows[0]["lot_Nos"].ToString());
if (dt5.Rows.Count > 0)
{
for (int i = 0; i <= dt5.Rows.Count - 1; i++)
{
foreach (DataGridViewRow r3 in dgvLKutai.Rows)
{
if (r3.Cells[1].Value.ToString() == dt5.Rows[i]["labourid"].ToString())
{
r3.Cells[0].Value = true;
r3.Cells[3].Value = decimal.Parse(dt5.Rows[i]["wagesamount"].ToString());
}
}
}
}
#endregion
#region Flekar Labour
DataTable dt6 = Mst.LabourWork(5, dt.Rows[0]["lot_Nos"].ToString());
if (dt6.Rows.Count > 0)
{
for (int i = 0; i <= dt6.Rows.Count - 1; i++)
{
foreach (DataGridViewRow r4 in dgvLFlekar.Rows)
{
if (r4.Cells[1].Value.ToString() == dt6.Rows[i]["labourid"].ToString())
{
r4.Cells[0].Value = true;
r4.Cells[3].Value = decimal.Parse(dt6.Rows[i]["wagesamount"].ToString());
}
}
}
}
#endregion
#region Packing Labour
DataTable dt7 = Mst.LabourWork(6, dt.Rows[0]["lot_Nos"].ToString());
if (dt7.Rows.Count > 0)
{
for (int i = 0; i <= dt7.Rows.Count - 1; i++)
{
foreach (DataGridViewRow r5 in dgvLPacking.Rows)
{
if (r5.Cells[1].Value.ToString() == dt7.Rows[i]["labourid"].ToString())
{
r5.Cells[0].Value = true;
r5.Cells[3].Value = decimal.Parse(dt7.Rows[i]["wagesamount"].ToString());
}
}
}
}
#endregion
#region Bora pack detail
DataTable dt8 = Database.ExecuteTextDataTable(Database._WF_APPLICATION(),"exec SP_Productiondetail 17,'"+ dt.Rows[0]["lot_Nos"].ToString()+"'");
if (dt8.Rows.Count > 0)
{
for (int i = 0; i <= dt8.Rows.Count - 1; i++)
{
foreach (DataGridViewRow r6 in dgvBoraPacking.Rows)
{
if (r6.Cells[1].Value.ToString() == dt8.Rows[i]["unitid"].ToString())
{
r6.Cells[0].Value= true;
r6.Cells[3].Value = decimal.Parse(dt8.Rows[i]["Unit_Quantity"].ToString());
}
}
}
}
#endregion
谢谢
Rajgir Raj
Thanks
Rajgir Raj
推荐答案
直接在datagridview数据源上工作,因为这提供了某种映射
就像那样
work directly on the datagridview datasource as this provide some kind of mapping
like that
foreach (DataRow row in ((DataTable)dataGridView1.DataSource).Rows)
{
row["Check"]=true;
}
这篇关于Datagridview复选框值以编程方式设置为true,但在视觉上未检查。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!