Cannot implicitly convert type 'object' to 'int'?

  • Thread starter Thread starter Michael Schindler
  • Start date Start date
M

Michael Schindler

frmHauptmenue.IntMandantID = (dataGridFiBuMandant[hti.Row, 0]);

Why?

What can I do? possible solution is, I convert this:

Convert.tostring(frmHauptmenue.IntMandantID) = (dataGridFiBuMandant[hti.Row,
0].tostring());

But, i would like not sring this is a integer...what can I do?

Thanks
 
frmHauptmenue.IntMandantID = (int)dataGridFiBuMandant[hti.Row, 0];

Assuming of course that the datagrid is holding an integer value at that
point.

Perhaps safer:

object gridValue = dataGridFiBuMandant[hti.Row, 0];
if (gridValue is int)
{
frmHauptmenue.IntMandantID = (int)gridValue;
}
else
{
... error handling ...
}

I suggest looking up boxing, unboxing, and casting.
 
Thank you

(int)....

This was the solution :-)

Thanks

Michael



Matt Garven said:
frmHauptmenue.IntMandantID = (int)dataGridFiBuMandant[hti.Row, 0];

Assuming of course that the datagrid is holding an integer value at that
point.

Perhaps safer:

object gridValue = dataGridFiBuMandant[hti.Row, 0];
if (gridValue is int)
{
frmHauptmenue.IntMandantID = (int)gridValue;
}
else
{
... error handling ...
}

I suggest looking up boxing, unboxing, and casting.

--
Regards,
Matt
(e-mail address removed)


Michael Schindler said:
frmHauptmenue.IntMandantID = (dataGridFiBuMandant[hti.Row, 0]);

Why?

What can I do? possible solution is, I convert this:

Convert.tostring(frmHauptmenue.IntMandantID) = (dataGridFiBuMandant[hti.Row,
0].tostring());

But, i would like not sring this is a integer...what can I do?

Thanks
 
Hi Michael,

It's actually much simpler:

frmHauptmenue.IntMandantID = (int)(dataGridFiBuMandant[hti.Row, 0]);
 
Back
Top