rwheeler23
asked on
VS 2008 C# Input string not in correct format
Why am I receiving a message about input string not of correct format on this line?
if (Int32.Parse(dgvFlagTransa ctionsView [9, dgvFlagTransactionsView.Cu rrentCell. RowIndex]. Value.ToSt ring()) == 0)
At first I did not have the Int32.Parse method but I had to add that because I got a message about == cannot be used with object or int.
I have a cell on a datagrid that has a checkbox. What I am trying to do is change the value in the actual field. So if it value was 0 change it to 1, if its value was one change it to 0. The value is in column 10 of the grid.
if (Int32.Parse(dgvFlagTransa
At first I did not have the Int32.Parse method but I had to add that because I got a message about == cannot be used with object or int.
I have a cell on a datagrid that has a checkbox. What I am trying to do is change the value in the actual field. So if it value was 0 change it to 1, if its value was one change it to 0. The value is in column 10 of the grid.
private void dgvFlagTransactionsView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
try
{
if (e.ColumnIndex == 0 && e.RowIndex >= 0)
{
if (Int32.Parse(dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value.ToString()) == 0)
{
dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value = 1;
}
else
{
dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value = 0;
}
}
}
catch (Exception ex)
{
string eMsg = "003E: ERROR: " + ex.Message;
if (stackTraceWanted) eMsg += "\n" + ex.StackTrace;
MessageBox.Show(eMsg);
}
}
missing an open parenthesis?
if( (Int32.Parse(dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value.ToString()) == 0)
or
if (Int32.Parse(dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value.ToString() == 0)
opps, ignore me pls= sorry
ASKER
I got it to work doing this. Not sure if this is the correct way to do it.
if (dgvFlagTransactionsView[9 , dgvFlagTransactionsView.Cu rrentCell. RowIndex]. Value.ToSt ring() == "False")
{
dgvFlagTransactionsView[9, dgvFlagTransactionsView.Cu rrentCell. RowIndex]. Value = true;
}
else
{
dgvFlagTransactionsView[9, dgvFlagTransactionsView.Cu rrentCell. RowIndex]. Value = false;
}
if (dgvFlagTransactionsView[9
{
dgvFlagTransactionsView[9,
}
else
{
dgvFlagTransactionsView[9,
}
looks like a toggle, does this work?
When you use == true in your if statement, does that generate an error too? (I'd think this is the same as NOT saying ==true, but i'm asking as a sanity check, because that value is what you are assigning lower down.)
dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value = !(dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value);
When you use == true in your if statement, does that generate an error too? (I'd think this is the same as NOT saying ==true, but i'm asking as a sanity check, because that value is what you are assigning lower down.)
ASKER
This does not work. It will not even build. I get
"Error 1 Operator '!' cannot be applied to operand of type 'object
Yes, it is simply a toggle. If it is false when clicked on change to true, if it is true when clicked on change to false.
"Error 1 Operator '!' cannot be applied to operand of type 'object
Yes, it is simply a toggle. If it is false when clicked on change to true, if it is true when clicked on change to false.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried using this but VS does not like this.
if (dgvFlagTransactionsView[9
How do I structure an if statement with a value that already is boolean?