A set of .NET Framework managed libraries for developing graphical user interfaces.
Hi @rahul kumar ,Welcome to Microsoft Q&A.
I used the previous code.
You just need to check whether the next line of the target line is a new line. If yes, create two new rows, if not, update the third row.
using System.Collections.Generic;
using System.Windows.Forms;
namespace _7_3_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();
if (dataGridView1.Rows[selectedCell.RowIndex + 1].IsNewRow)
{
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);
}
else
{
dataGridView1.Rows[selectedCell.RowIndex + 2].Cells[1].Value = $"{price} cr";
}
}
}
}
}
}
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.