Hi @Rahul Kumar , Welcome to Microsoft Q&A.
I simulated the results you get using a dictionary.
Use the valuechange event to trigger the judgment.
Only when the current cell is the second column every 3 cells will be triggered:
using System.Collections.Generic;
using System.Windows.Forms;
namespace _6_14_x
{
public partial class Form1 : Form
{
Dictionary<string, string> cusList = new Dictionary<string, string>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, System.EventArgs e)
{
cusList.Add("deepak(market)", "21.00");
cusList.Add("xxx(market)", "10.00");
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.SelectedCells.Count > 0)
{
DataGridViewCell selectedCell = dataGridView1.SelectedCells[0];
if (selectedCell.ColumnIndex == 1 && (selectedCell.RowIndex % 3 == 0))
{
string name = dataGridView1.Rows[selectedCell.RowIndex].Cells[0].Value.ToString();
cusList.TryGetValue(name, out string value);
string price = selectedCell.Value.ToString();
DataGridViewRow row1 = new DataGridViewRow();
row1.CreateCells(dataGridView1, $"Cur Bal:{value} Dr", "");
DataGridViewRow row2 = new DataGridViewRow();
row2.CreateCells(dataGridView1, "On Account", $"{price} cr");
dataGridView1.Rows.Add(row1);
dataGridView1.Rows.Add(row2);
}
}
}
}
}
This code only demonstrates how to add two required lines as needed, you also need to add reckless judgment as needed.
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly 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.