English 中文(简体)
如何检查数据网格内检查箱是否经过检查
原标题:How to check whether Check box inside data grid view is checked or not

如何对<代码>bool的核对箱状况进行检查,该箱载于datagridview。 如果不加检查,我谨有<代码>true。 任何人都可以帮助我。

可在<条码>中处理。

最佳回答

在数据GridViewhere

他们尤其说:

For clicks in a DataGridViewCheckBoxCell, this event occurs before the check box changes value, so if you do not want to calculate the expected value based on the current value, you will typically handle the DataGridView.CellValueChanged event instead. Because that event occurs only when the user-specified value is committed, which typically occurs when focus leaves the cell, you must also handle the DataGridView.CurrentCellDirtyStateChanged event. In that handler, if the current cell is a check box cell, call the DataGridView.CommitEdit method and pass in the Commit value.

因此,他们建议不要使用手机Click型事件(因为这些事件在你离开囚室之前从未推过价值),而是使用当前CellDirtyState。 改变和混合式方法。

因此,你最后说:

dataGridView1.CurrentCellDirtyStateChanged += new EventHandler(dataGridView1_CurrentCellDirtyStateChanged);
dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);

void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
    if (dataGridView1.Columns[e.ColumnIndex].Name == "CB")
    {
        MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());    
    }
}

void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
    dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}

而且,为了获得核实价值,这只是数据GridViewCheckBoxCell的价值财产。

因此,请:

dataGridView1.Rows[rowindex].Cells[cellindex].Value 

你们的保值与检查箱相当(在变革之后)。

问题回答

如果设计人对检查箱进行定义,那么检查箱的名称就简单明了,并检查其真实/伪造的“检查”财产。

但是,我怀疑你正在通过编码将检查箱添加到数据网中?

in this case youll have to save a reference to the checkbox somwhere. If i where you i would add all the checkboxes that i add to the datagrid to a list or if you want to refer to them by name i would add them to a dictionary.

您还可以把一项活动与检查箱联系起来。 改变活动,选择它,点击财产小组中几乎没有的编号icon,并找到检查结果 变造和翻倍。

in the event-code you can obtain the checkbox clicked by typing: CheckBox mycheckbox = sender as CheckBox;

and then refering to mycheckbox.checked to get a bool for if its checked or not.

你可以尝试以这种方式做到这一点,例如,如果你根据你能够发现的被检查国家的指数,将电网连接起来。

bool IsChecked = Convert.ToBoolean((dataGridView1[ColumnIndex, RowIndex] as DataGridViewCheckBoxCell).FormattedValue))
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    var checkcell = new DataGridViewCheckBoxCell();
    checkcell.FalseValue = false;
    checkcell.TrueValue = true;
    checkcell.Value = false;
    dataGridView1[0, 0] = checkcell; //Adding the checkbox

    if (((bool)((DataGridViewCheckBoxCell)dataGridView1[0, 0]).Value) == true)
    {
        //Stuff to do if the checkbox is checked
    }
}

工作率为100%。

 private void grd_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

            grd.CommitEdit(DataGridViewDataErrorContexts.Commit);
            bool Result = Convert.ToBoolean((grd[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell).Value);
        }




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签