Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

iam stuck here plz urgent give me a solution of my below error
C#
private void dgvWpRate_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            label132.Text = dgvWpRate.Rows[0].Cells[0].Value.ToString();
            label133.Text = dgvWpRate.Rows[1].Cells[0].Value.ToString();
        }

datagridview have 1column and 6rows,i want to pass the value (means using numbers only)
to label.text.
i have six labels to get the six rows values.
when i click on datagridview cell show below error
An unhandled exception of type 'System.NullReferenceException' occurred in test.exe

Additional information: Object reference not set to an instance of an object.
Posted
Updated 1-Nov-14 6:36am
v2

1 solution

try below code, you may have null values for cell values.
C#
label132.Text = dgvWpRate.Rows[0].Cells[0].Value as string;
 label133.Text = dgvWpRate.Rows[1].Cells[0].Value as string;
 
Share this answer
 
v2
Comments
cadsolution 1-Nov-14 13:15pm    
how to pass the value to label from datagridview cell automatically when i change the value with out any click.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900