Aditya B

Aditya B

  • NA
  • 6
  • 2.8k

Message box for the replaced values count

Feb 3 2016 5:07 AM
Hi,
I have a task called Find and Replace in the DataGridView - It's completed.But i want the replaced count in the message box - I'm getting it. But i'm getting the count as 30 irrespective of the replaced values.

Can anyone help me how to achieve this? Below is my Find and Replace code:
 
 
private void btnFindandReplace_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
for (int i = 0; i <= dataGridView1.Columns.Count - 1; i++)
{
f.cmbColumnCombo.Items.Add(dataGridView1.Columns[i].Name);
}
f.ShowDialog();
  
if (recNo > 0)
recNo = recNo - 30;
LoadPage(MyFOrmat, true);
}


public void LoadPage(string Format, bool isFindAndReplace = false)
{
int replaced = 0;
int startRec;
int endRec;
if (currentPage == PageCount)
{
endRec = (int)maxRec;
}
else
{
endRec = (int)pageSize * currentPage;
}
dataGridView1.Rows.Clear();
if (recNo == 0)
{
dataGridView1.Columns.Clear();
}
int rowindex = 0;
startRec = recNo;
for (int RowCount = startRec; RowCount <= endRec; RowCount++)
{
if (datfile[RowCount].ToString() != "" )
{
if (RowCount == 0)
{
string[] column = datfile[RowCount].Split('þ');
for (int i = 0; i < column.Length - 1; i++)
{
if (column[i].ToString() != "") //if (column[i].ToString() != "" && column[i].ToString() != "\u0014")
{
DataGridViewTextBoxColumn dgvtxtcountry = new DataGridViewTextBoxColumn();
dgvtxtcountry.HeaderText = column[i].ToString();
dgvtxtcountry.Name = column[i].ToString();
dataGridView1.Columns.Add(dgvtxtcountry);
cmbList.Add(column[i]);
i += 1;
}
}
}
if (RowCount != 0)
{
dataGridView1.Rows.Add();
string[] column = datfile[RowCount].Split('þ');
int index = 0;
for (int i = 1; i < column.Length - 1; i++)
{
if (column[i].ToString() != "\u0014")
{
dataGridView1.Rows[rowindex].Cells[index].Value = column[i].Trim('þ');
if (StaticVar.FnR == true && index == StaticVar.colindx)
{
if ((column[i]).Contains(StaticVar.Find) != null)
dataGridView1.Rows[rowindex].Cells[index].Value = column[i].Replace(StaticVar.Find, StaticVar.Replace);
replaced++;
}
if (StaticVar.DateFormat != "" && StaticVar.DateFormat != null)
{
if (StaticVar.datecolidx == ((i - 1) / 2))
{
dataGridView1.Rows[rowindex].Cells[index].Value = Convert.ToDateTime(column[i]).ToString(StaticVar.DateFormat);
}
}
index += 1;
i += 1;
}
}
rowindex += 1;
}
}
recNo += 1;
}
if (isFindAndReplace)
{
MessageBox.Show(string.Format("No: of values replaced is: {0}", replaced));
}
}
 
 
 

Answers (2)