@Sushil Agarwal , Sorry for the late response, based on my test, I almost reproduced your problem.
Please remove the rows in dgvPickList after you press the tnCheckPickOk if you want to show no records in dgvPickList.
You could try the following code:
private void btnCheckPickOk_Click(object sender, EventArgs e)
{
string query;
//dgvPickList.DataSource as DataTable).DefaultView.RowFilter)
if (string.IsNullOrWhiteSpace((dgvPickList.DataSource as DataTable).DefaultView.RowFilter))
{
query = "qtyPickedTotal <> Qty and MrpScaned<>MRP_Unit";
lblFilter.Text = "Filtered Pick List";
}
else
{
query = string.Empty;
lblFilter.Text = "UnFiltered Pick List";
}
//(dgvPickList.DataSource as DataTable).DefaultView.RowFilter = query;
(dgvPickList.DataSource as DataTable).DefaultView.RowFilter = query;
dgvPickList.Refresh();
int index = 0;
int rowsCount = dgvPickList.Rows.Count - 1;
lblFilter.Text += " " + rowsCount.ToString() + "/" + dtpicklistItems.Rows.Count.ToString();
if (rowsCount > 0)
{
for (int item = 0; item < rowsCount; item++)
{
//verify if the next rows is visible
if (dgvPickList.Rows[(item + 1)].Visible)
{
decimal.TryParse(dgvPickList["qtyPickedTotal", item].Value.ToString(), out decimal qtyPickedTotal);
decimal.TryParse(dgvPickList["Qty", item].Value.ToString(), out decimal Qty);
decimal.TryParse(dgvPickList["MRP_Unit", item].Value.ToString(), out decimal MRP_Unit);
decimal.TryParse(dgvPickList["MrpScaned", item].Value.ToString(), out decimal MrpScaned);
if (qtyPickedTotal.Equals(Qty)
&& MRP_Unit.Equals(MrpScaned))
{
dgvPickList.Rows[item].DefaultCellStyle.BackColor = Color.Gold;
index = item;
}
}
}
}
dgvPickList.Rows.RemoveAt(index);
}
Result:
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.