当鼠标进入单元格时,如何使单元格值为null? [英] How to make cell value null when mouse enter in cell?

查看:87
本文介绍了当鼠标进入单元格时,如何使单元格值为null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当鼠标进入鼠标选定的单元格时,如何使单元格值为null或为空。



我尝试过:



How to make cell value null or empty when mouse enter in that mouse selected cell.

What I have tried:

private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
          
            foreach (DataGridViewRow dr in dataGridView1.SelectedRows)
            {
                dr.Cells["cal_qty"].Value = "";
            }
        }

推荐答案

好吧,正如你问过这个问题一样,这可能会有效你创建了CellMouseEnter事件



Well, as you've asked the question, this 'might' work if you create the CellMouseEnter event

private void dataGridView1_CellMouseEnter(object sender,
    DataGridViewCellEventArgs e)
{
    DataGridViewCell cell = 
            this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
    cell.Value = "";

}





但是,我不确定它是否真的需要(想要!=需要) - 如果你在datagridview周围挥动鼠标,这可能会消灭任何/所有细胞



经过一番想法我可能会错误地解释你所问的内容,因此,不是使用CellMouseEnter,而是将上述事件过程中的两行添加到SelectionChanged事件中 - 即





but, Im not sure if its what you actually NEED (want != need) - if you're waving the mouse around your datagridview, this could wipe out any/all cells

after some thought I might be mis-interpreting what you've asked, so, instead of using CellMouseEnter, add the two lines in the event procedure above to the SelectionChanged event - ie

private void dataGridView1_SelectionChanged(object sender,
    DataGridViewCellEventArgs e)
{
    DataGridViewCell cell = 
            this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
    cell.Value = "";

}


这篇关于当鼠标进入单元格时,如何使单元格值为null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆