0

i have 6 column in which the first column is a textboxcell and the rest are checkboxes. and i want to put the value of two dimensional array to the datagrid.

string[,] debugger={{"name","0","0","1","1","0"}};

0=false 1=true (i assigned false value and true value from the datagridview property window. when i try this it gives me a format exception ?

grdFont.ColumnCount=6;
            var row = new DataGridViewRow();
            row.Cells.Add(new DataGridViewTextBoxCell()
            {
               Value = debugger[0] 
            });
            row.Cells.Add(new DataGridViewCheckBoxCell()
            {
                Value = debugger[1]
            });
            row.Cells.Add(new DataGridViewCheckBoxCell()
            {
                Value = debugger[2]
            });
            row.Cells.Add(new DataGridViewCheckBoxCell()
            {
                Value = debugger[3]
            });
            row.Cells.Add(new DataGridViewCheckBoxCell()
            {
                Value = debugger[4]
            });
            row.Cells.Add(new DataGridViewCheckBoxCell()
            {
                Value = debugger[5]
            });
            grdFont.Rows.Add(row);

is there another way i can implement this?

Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81
Serak Shiferaw
  • 993
  • 2
  • 11
  • 32

1 Answers1

0

0 is not equvalent of false and 1 is not equivalent of true. Write a function to convert these numbers to Boolean value:

public bool ConvertNumberToBoolean(int number)
{
    if (number == 0)
    {
        return false;
    }
    else
    {
        return true;
    }
}

Use this function when you set a value to cell:

row.Cells.Add(new DataGridViewCheckBoxCell()
{
    Value = ConvertNumberToBoolean(Convert.ToInt32(debugger[1]));
});

It's a pretty basic realization, but I believe you got the idea

Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162
  • ya i know but what is (FalseValue and TrueValue) property for inside visual studio? [link] http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcolumn.falsevalue.aspx – Serak Shiferaw Feb 04 '13 at 08:48