Hi gokuldas,
Refer below sample.
Code
C#
private void Form1_Load(object sender, EventArgs e)
{
DataGridViewTextBoxColumn txtAmount = new DataGridViewTextBoxColumn();
txtAmount.HeaderText = "Amount";
txtAmount.Name = "txtAmount";
txtAmount.Width = 100;
DataGridViewTextBoxColumn txtPercentage = new DataGridViewTextBoxColumn();
txtPercentage.HeaderText = "Percentage";
txtPercentage.Name = "txtPercentage";
txtPercentage.Width = 100;
dataGridView1.Columns.Insert(0, txtPercentage);
dataGridView1.Columns.Insert(1, txtAmount);
this.dataGridView1.CellValidating += new
DataGridViewCellValidatingEventHandler(dataGridView1_CellValidating);
}
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
string headerText = dataGridView1.Columns[e.ColumnIndex].HeaderText;
int percentage = Convert.ToInt16(e.FormattedValue);
if (!headerText.Equals("Percentage")) return;
dataGridView1[e.ColumnIndex + 1, e.RowIndex].Value = 0;
}
VB.Net
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)Handle Me.Load
Dim txtAmount As DataGridViewTextBoxColumn = New DataGridViewTextBoxColumn()
txtAmount.HeaderText = "Amount"
txtAmount.Name = "txtAmount"
txtAmount.Width = 100
Dim txtPercentage As DataGridViewTextBoxColumn = New DataGridViewTextBoxColumn()
txtPercentage.HeaderText = "Percentage"
txtPercentage.Name = "txtPercentage"
txtPercentage.Width = 100
dataGridView1.Columns.Insert(0, txtPercentage)
dataGridView1.Columns.Insert(1, txtAmount)
Me.dataGridView1.CellValidating += New DataGridViewCellValidatingEventHandler(AddressOf dataGridView1_CellValidating)
End Sub
Private Sub dataGridView1_CellValidating(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs)
Dim headerText As String = dataGridView1.Columns(e.ColumnIndex).HeaderText
Dim percentage As Integer = Convert.ToInt16(e.FormattedValue)
If Not headerText.Equals("Percentage") Then Return
dataGridView1(e.ColumnIndex + 1, e.RowIndex).Value = 0
End Sub
Screenshot