Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Not getting the cell value of a datagridview on CellLeave event
 

Not getting the cell value of a datagridview on CellLeave event

Hi,

I am calculating the datagridview column2 based on column1 value which is a input field.

I am doing this on datagridview cellLeave event. But firsttime When I enter some numeric value on column1 and tab out I am not getting the value of column1 but getting that in second time.

How could I get the value as soon as I tab out.

Here is my code.

private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)

{

if (dataGridView1.Rows[e.RowIndex].IsNewRow) { return; }

if (e.ColumnIndex != 0)

{

return;

}

else

{

if (!string.IsNullOrEmpty(dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString()))

{

decimal val = Convert.ToDecimal(dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString());

decimalval1 = Convert.ToDecimal(dataGridView1[2, e.RowIndex].Value.ToString());

decimalval2 = Convert.ToDecimal(dataGridView1[3, e.RowIndex].Value.ToString());

decimalval3 = val * (val1 + val2);

dataGridView1[1, e.RowIndex].Value = val3;

}

}

}

Please help.

Thanks!!

rpat  Saturday, June 07, 2008 7:57 PM

I have tried with CellEndEdit event instaed of CellLeave event and is working fine.

Thanks!!

rpat  Saturday, June 07, 2008 8:09 PM

I have tried with CellEndEdit event instaed of CellLeave event and is working fine.

Thanks!!

rpat  Saturday, June 07, 2008 8:09 PM

You can use google to search for other answers

Custom Search

More Threads

• Update Command and DataSet Designer
• Data Detail View Using Visual Studio Express (C#)
• help with datagrid after insert
• High lighted row in datagrid?
• Issue with custom datagridview column
• using XSD to convert objects?
• How do I add radiobuttons to a dataGrid
• Designer doesn't generate code for Databindings in an IBindableComponent
• Updating DataGridViewComboBoxColumn after external changes
• Issue with DataGridView / CellMouseClick