Click here to Skip to main content
16,019,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to make cell value null or empty when mouse enter in that mouse selected cell.

What I have tried:

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

1 solution

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

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

}


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

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

}
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 18-Apr-16 2:48am    
5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900