Home Forums WinForms controls Xceed Grid for WinForms runtime checkbox column

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15840 |

    hi, im new with this control (and .net),
    i have a grid populated by a datatable, but one column is 1 or 0, and i want to show it like a chekbox.

    mi code is like this (simplifyied):

    SqlConnection myConnection = new SqlConnection(myConnectionString);
    SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection);
    myConnection.Open();
    SqlDataReader myReader = myCommand.ExecuteReader();

    DataTable dtblData = new DataTable();
    dtblData.Load(myReader);

    xgrdCondicionPago.DataSource = dtblData;

    my grid gets populated, but the column shows only 1, 0 and null.

    how can i do?. thanks in advance.

    Imported from legacy forums. Posted by jrivam (had 3399 views)

    User (Old forums)
    Member
    Post count: 23064

    i’ve found a way, but the checkbox columns appear disabled, while the text columns not.
    there is code that i’ve added after:

    xgrdCondicionPago.Columns[“flag_por_defecto_documento”].CellViewerManager = new Xceed.Grid.Viewers.CheckBoxViewer();
    xgrdCondicionPago.Columns[“flag_por_defecto_documento”].CellEditorManager = new Xceed.Grid.Editors.CheckBoxEditor();

    btw, the select i’m using is : “select cp.id_condicion_pago, cp.descripcion, ” +
    “convert(int, isnull(clicp.flag_por_defecto_documento, 0)) as flag_por_defecto_documento ” +
    “from cliente_condicion_pago clicp ” +
    “inner join condicion_pago cp ” +
    “on clicp.cia=cp.cia ” +
    “and clicp.id_condicion_pago=cp.id_condicion_pago ” +
    “where clicp.cia=@sParamCia ” +
    “and clicp.id_cliente=@sParamCliente “

    where the third column is the checkbox column, and then database column “flag_por_defecto_documento” is varchar(1) (values 1, 0 and null).

    how can i enable the checkbox colum? or am i doing something wrong? thanks.

    Imported from legacy forums. Posted by jrivam (had 233 views)

    User (Old forums)
    Member
    Post count: 23064

    i’ve found another way, in the select instead of convert to int, converting to bit, so the grid know is a boolean column, and then, shows it as a checkbox. and no need of the 2 extra lines.

    “select cp.id_condicion_pago, cp.descripcion, ” +
    “convert(BIT, isnull(clicp.flag_por_defecto_documento, 0)) as flag_por_defecto_documento ” +
    “from cliente_condicion_pago clicp ” +
    “inner join condicion_pago cp ” +
    “on clicp.cia=cp.cia ” +
    “and clicp.id_condicion_pago=cp.id_condicion_pago ” +
    “where clicp.cia=@sParamCia ” +
    “and clicp.id_cliente=@sParamCliente “);
    but still, i cant edit it.

    Imported from legacy forums. Posted by jrivam (had 229 views)

    User (Old forums)
    Member
    Post count: 23064

    but still, i cant edit the checkbox column. anyone, please help.

    Imported from legacy forums. Posted by jrivam (had 255 views)

    Xceed Support
    Member
    Post count: 5658

    Here is some sample code with a 2-columns DataTable (1 Boolean column and 1 Integer column). You can edit both column’s value.

    <code>
    private void Form1_Load( object sender, EventArgs e )
    {
    //Create a DataTable
    DataTable dt = new DataTable();
    DataColumn dcBool = new DataColumn();
    dcBool.ColumnName = “BoolColumn”;
    dcBool.DataType = System.Type.GetType( “System.Boolean” );
    dt.Columns.Add( dcBool );

    DataColumn dcInt = new DataColumn();
    dcInt.ColumnName = “IntColumn”;
    dcInt.DataType = System.Type.GetType( “System.Int32” );
    dt.Columns.Add( dcInt );

    for( int i = 0; i < 50; i++ )
    {
    System.Data.DataRow row = dt.NewRow();
    int j = i % 3;

    if( j == 0 )
    {
    row[ “BoolColumn” ] = false;
    row[ “IntColumn” ] = 0;
    }
    else if( j == 1 )
    {
    row[ “BoolColumn” ] = true;
    row[ “IntColumn” ] = 1;
    }
    else
    {
    row[ “BoolColumn” ] = DBNull.Value;
    row[ “IntColumn” ] = DBNull.Value;
    }

    dt.Rows.Add( row );
    }

    gridControl1.DataSource = dt;

    gridControl1.Columns[ “IntColumn” ].CellEditorManager = new CheckBoxEditor();
    gridControl1.Columns[ “IntColumn” ].CellViewerManager = new CheckBoxViewer();
    }
    </code>

    Imported from legacy forums. Posted by CharlesB (had 4846 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.