Hi,
I have added the winform application example code, which has four columns. First column accept the student id then fetch the name in next column. Second column accept the school number which fetch the school name in another column.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WinFormApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Dictionary<int, string> studentCollection = new Dictionary<int, string>
{
[001] = "S1",
[002] = "S2",
[003] = "S3",
[004] = "S4",
};
Dictionary<int, string> schoolCollection = new Dictionary<int, string>
{
[011] = "S1",
[022] = "S2",
[033] = "S3",
[044] = "S4",
};
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
{
var cellValue = Convert.ToString(this.dataGridView1[e.ColumnIndex, e.RowIndex].Value);
int keyValue;
if(int.TryParse(cellValue, out keyValue))
{
if (e.ColumnIndex == 0)
{
var student = studentCollection[keyValue];
this.dataGridView1[1, e.RowIndex].Value = student;
}
else if (e.ColumnIndex == 2)
{
var school = schoolCollection[keyValue];
this.dataGridView1[3, e.RowIndex].Value = school;
}
}
}
}
}
}