Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • Last Modified:

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(dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value.ToString()) == 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.
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);
            }

        }

Open in new window

0
rwheeler23
Asked:
rwheeler23
  • 4
  • 3
1 Solution
 
rwheeler23Author Commented:
I just discovered that the value in that cell is actually of bit type.

I tried using this but VS does not like this.
if (dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value)

How do I structure an if statement with a value that already is boolean?

0
 
KorbusCommented:
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)

Open in new window

0
 
KorbusCommented:
opps, ignore me pls= sorry
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
rwheeler23Author Commented:
I got it to work doing this. Not sure if this is the correct way to do it.

if (dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value.ToString() == "False")
                    {
                        dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value = true;
                    }
                    else
                    {
                        dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value = false;
                    }
0
 
KorbusCommented:
looks like a toggle, does this work?
dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value = !(dgvFlagTransactionsView[9, dgvFlagTransactionsView.CurrentCell.RowIndex].Value);

Open in new window


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.)

0
 
rwheeler23Author Commented:
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.
0
 
KorbusCommented:
Can you determine what CLASS the boolean value is?  The class it self may have some way to invert the value with a function call.  It might also have specific enumerated values in it.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now