DataGridView _CellValueChanged is not firing

Posted by S.kanthula under C# on 11/8/2011 | Points: 10 | Views : 5392 | Status : [Member] | Replies : 2
Dear All

I have an windows application in which i'm using DataGridView control to show the data and in this i have a column as Grand Total Remaing are like sub1,Sub2,Sub3 etc

What i wanted to do is when user enters the values for Sub1 to Sub3 I want to show the Total Sum in the Grand Total Column

For this i have used _CellValueChanged ,this event is working fine when i kept a breakpoint and debug i'm getting the total value ,but if i remove the breakpoint i'm not getting any value ..
Please help me out
here is my sample code

datagridcontrol = (DataGridControl)wfhdgPestSplit.Child;
public CompanyWise()
{
datagridcontrol.dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
}

void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//throw new NotImplementedException();
int column = e.ColumnIndex;
int row = e.RowIndex;
string str = datagridcontrol.dataGridView1[column, row].Value.ToString();

DataView dtDetails = new DataView();
dtDetails = (DataView)datagridcontrol.dataGridView1.DataSource;


GrandTotal(datagridcontrol.dataGridView1, row, column, 3);
}

private void GrandTotal(DataGridView dataGridView, int iRow, int iColumn, int iResultColumn)
{
DataView dtDetails = new DataView();
dtDetails = (DataView)dataGridView.DataSource;
int value = 0;
int value1 = 0;
for (int columnNo = 4; columnNo < dtDetails.Table.Columns.Count; columnNo++)
{
if (!string.IsNullOrEmpty(dtDetails.Table.Rows[iRow][columnNo].ToString()))
value = Convert.ToInt32(dtDetails.Table.Rows[iRow][columnNo].ToString());
else
value = 0;

if (value != 0)
{
value1 = value + value1;
}
}
dtDetails[iRow][iResultColumn] = value1;
//System.Windows.Forms.MessageBox.Show("Value is " + value1 + "and current value is " + value);
//datagridcontrol.dataGridView1.DataSource = dtDetails;
dataGridView.DataSource = dtDetails;
}
Best Regards




Responses

Posted by: Umeshdwivedi on: 11/9/2011 [Member] Starter | Points: 25

Up
0
Down
the problem is in the last line of your code.

dataGridView.DataSource = dtDetails;

if you bind the grid once again... it will overwrite everything happened

Latest Technology Trainer
And Part time software consultant

S.kanthula, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: S.kanthula on: 11/9/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Umeshdwivedi

Thanks for your replay
but i solved it,
i have updated the dataview and i bind the grid view then it is working fine
here is my code
dataGridView.DataSource = dtDetails.Table.AcceptChanges();

S.kanthula, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response