Click here to Skip to main content
15,912,504 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hsi,
I'm new to c#.net. I have being wonder is it possible to convert data from datagridview into variables?

for example
let say from datagridview A

equations name | equations
wen | w + w + q + e

it will become

string wen = w + w + q + e;

from datagridview B

variable | value
w | 1
q | 0.2
e | 2

will become

double w = 1;
double q = 0.2;
double e = 2;

Thank you.
Posted

1 solution

Yes, you can get the value of cell using dataGridView1.CurrentCell.Value see example:
C#
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
    double cellValue;
    bool result = Double.TryParse(dataGridView1.CurrentCell.Value.ToString(), out cellValue);
    if (result)
        MessageBox.Show(cellValue.ToString());
    else
        Console.WriteLine("cell value could not be parsed.");
}

refer: datagridview[^]
 
Share this answer
 

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