Reputation: 121
I am trying to get data from cells from my dataGridView in windows form, bu keep getting this error: 'System.Windows.Forms.DataGridViewCell' does not contain a definition for 'Text'... (are you missing a using directive or an assembly reference?). I use the same method in a gridwiev in a related asp.net web forms applicatio, so why does it not work here? Data in datagridview is from a database.
new Rectangle
{
Height = Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Text),
Width = Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Text),
X = 0,
Y = 0,
};
Upvotes: 1
Views: 1345
Reputation: 14517
It doesn't work here because a DataGridView
is not the same as the ASP GridView
. They may perform the same sort of work, but they do so differently. I'm not familiar with the GridView
, so I can't point out any differences other than the one you just observed.
A DataGridViewCell
contains a reference to an Object
and has members for controlling how that object is transformed into a "formatted value" for display. It's fairly complex and ultimately you should read up on it, but without knowing anything about the underlying value, we can guess that this might work for you:
Height = Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value)
Upvotes: 4