DataGridViewCheckBoxCell如何当窗体加载过程中设置为显示检查 [英] DataGridViewCheckBoxCell how to show checked when set during form load
问题描述
我有一个DataGridView加载数据从数据表,连同DataGridViewCheckBoxCells的绑定列。都在DataGridView的行与值的单独的数据表相比,用户已保存,并且,如果有一个匹配,该行的复选框应该检查
I have a DataGridView that loads data from a DataTable, along with an unbound column of DataGridViewCheckBoxCells. The rows in the DataGridView are compared with a separate DataTable with values the user has saved, and if there is a match, the checkbox for that row should check.
下面是code的比较值,并将复选框价值为true:
Here is the code that compares the values and sets the checkbox value to 'true':
foreach (int j in selectedObjectives)
{
foreach (DataGridViewRow r in dgvObjectives.Rows)
{
if (j == Convert.ToInt32(r.Cells["ObjectiveID"].Value))
{
dgvObjectives.CurrentCell = r.Cells["Select"];
((DataGridViewCheckBoxCell)r.Cells["Select"]).Value = true;
//dgvObjectives.InvalidateCell(r.Cells["Select"]);
//dgvObjectives.EndEdit();
//dgvObjectives.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
if (Convert.ToInt32(r.Cells["ObjectiveID"].Value) == selectedIndex)
{
r.Selected = true;
}
}
}
当我调用该方法的形式负载私人无效WQMDrill_Load(对象发件人,EventArgs五)
,该值是否设置正确时执行该操作,但复选框做不检查。但是,当窗体加载完成后调用,code完美的作品。不幸的是我,我绝对需要为这些在加载过程检查。
When I call the method to perform this action during the form load private void WQMDrill_Load(object sender, EventArgs e)
, the values are set correctly, but the checkboxes do not check. However, when called after the form is finished loading, the code works perfectly. Unfortunately for me, I absolutely need for these to check during the load process.
我希望我很清楚我的问题,在这个问题上的任何帮助将不胜AP preciated。正如你所看到的,我已经试过单独的单元格,以及整个的DataGridView控制无效。我也有
I hope I was clear with my issue, any help on this matter would be greatly appreciated. As you can see, I have tried to invalidate the cell alone, as well as the entire DataGridView control. I also have
private void dgvObjectives_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (this.dgvObjectives.CurrentCell.ColumnIndex == 0)
{
this.dgvObjectives.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
这不会在这段时间火。谢谢你。
That doesn't fire during this time. Thank you.
推荐答案
您可以把您的复选框的选择和更新逻辑在DataBindingComplete事件处理程序,将显示给用户的FormLoad之后,但任何在此之前火。
You can put your checkbox selection and update logic in the DataBindingComplete eventhandler, this fires after the FormLoad but before anything is displayed to the user.
这篇关于DataGridViewCheckBoxCell如何当窗体加载过程中设置为显示检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!