Home Forums WinForms controls Xceed Grid for WinForms Adding a ComboBox to a column

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

    Hello,

    I’m using .net 2003 c# with xceed grid 3.2 with v2.5 license.

    I can add a CheckBox at runtime to a row but I can’t add a combobox. I have seen several post with comboboxes but none of them helps me (checkbox is visible but not combobox).

    What i really need is datarows with a checkbox, a combobox and other string and image columns and i must react to checkbox CheckedChanged and combobox SelectedIndexChanged events of each row. When checkbox_checkedchanged is fired in a row, i must change the list displayed on the comboboxes of this and other rows and when combobox_selectedindexchanged is fired i need to change the selectedindex of the comboboxes on other rows.

     Can anybody help me, better with c# code.

    Thanks.

     

    Imported from legacy forums. Posted by Javier (had 4305 views)

    User (Old forums)
    Member
    Post count: 23064

    Do you get any exception?  If not, it is possible there is one, but you don’t see because it is swallowed by the grid or the framework.

    Is the debugger set to break on all exceptions? (Debug Menu -> Exceptions -> Common Language Runtime Exception, then select “Break into the debugger” radio button).  This will make sure that no exceptions are swallowed by the grid or the framework, and that the debugger will break in any part of the code.

    Imported from legacy forums. Posted by André (had 416 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks André for your attention. No, i don’t get any exception and none is swallowed by the framework.

     This is my code:

    //Checkbox 

    grid.Columns.Add(

    new Column(“chkPublicar”, typeof(bool)));

    grid.Columns[“chkPublicar”].CellViewer =

    new Xceed.Grid.Editors.GridCheckBox();

    grid.Columns[“chkPublicar”].CellEditor =

    new Xceed.Grid.Editors.GridCheckBox();

    //Combobox 

    grid.Columns.Add(

    new Column(“cmbOrden”, typeof(int)));

    grid.AddingDataRow +=

    new AddingDataRowEventHandler(grid_AddingDataRow);

    grid.ReadOnly =

    false;

    grid.SingleClickEdit =

    true;

    grid.Columns[“chkPublicar”].ReadOnly =

    false;

    grid.Columns[“cmbOrden”].ReadOnly =

    false;

     

    private void grid_AddingDataRow(object sender, AddingDataRowEventArgs e)

    {

    e.DataRow.Cells[“chkPublicar”].Value = (estado == 2);

    e.DataRow.Cells[“chkPublicar”].Click +=

    new EventHandler(chkPublicar_Click);

    Xceed.Grid.Editors.GridComboBox cmb =

    new Xceed.Grid.Editors.GridComboBox();

    cmb.Items.Add(1);

    cmb.Items.Add(2);

    cmb.Items.Add(3);

    cmb.SelectedIndex = 1;

    cmb.Enabled =

    true;

    cmb.Visible =

    true;

    cmb.DropDownStyle = ComboBoxStyle.DropDownList;

    cmb.DropDownWidth = 40;

    cmb.SelectedIndexChanged +=

    new EventHandler(cmb_SelectedIndexChanged);

    e.DataRow.Cells[“cmbOrden”].CellViewer = cmb;

    e.DataRow.Cells[“cmbOrden”].CellEditor = cmb;

    }

     

    I use Click event because i don’t know how to trigger the CheckedChanged event

    private void chkPublicar_Click(object sender, EventArgs e)

    {

    bool valor = Convert.ToBoolean(((Xceed.Grid.DataCell)sender).Value);

    ((Xceed.Grid.DataCell)sender).Value = !valor;

    }

    private void cmb_SelectedIndexChanged(object sender, EventArgs e)        //<=== Never fired

    {

    int idx = ((Xceed.Grid.Editors.GridComboBox)sender).SelectedIndex;

    Console.WriteLine(idx.ToString());

    }

    What i’m doing wrong?

     Thanks. 

     

    Imported from legacy forums. Posted by Javier (had 690 views)

    User (Old forums)
    Member
    Post count: 23064

    Unfortunately, we can’t identify the issue.  We have tried the following code, and it works fine in with version 3.2 using a 2.5 license key :

     

        public Form1()

        {

          Xceed.Grid.Licenser.LicenseKey = “GRD25…”;

          InitializeComponent();

        }

     

       

    private void Form1_Load( object sender, EventArgs e )

        {

          GridControl gridControl = new GridControl();

          gridControl.SingleClickEdit = true;

          gridControl.FixedHeaderRows.Add( new ColumnManagerRow() );

          gridControl.Dock = DockStyle.Fill;

          this.Controls.Add( gridControl );

     

          //Checkbox

     

          gridControl.Columns.Add( new Column( “chkPublicar”, typeof( bool ) ) );

          gridControl.Columns[ “chkPublicar” ].CellViewer = new Xceed.Grid.Editors.GridCheckBox();

          gridControl.Columns[ “chkPublicar” ].CellEditor = new Xceed.Grid.Editors.GridCheckBox();

     

          //Combobox

          gridControl.Columns.Add( new Column( “cmbOrden”, typeof( int ) ) );

          gridControl.AddingDataRow += new AddingDataRowEventHandler( gridControl_AddingDataRow );

     

     

          gridControl.DataRows.AddNew().EndEdit();

     

        }

     

        private void gridControl_AddingDataRow( object sender, AddingDataRowEventArgs e )

        {

          Xceed.Grid.Editors.GridComboBox cmb = new Xceed.Grid.Editors.GridComboBox();

     

          cmb.Items.Add( 1 );

          cmb.Items.Add( 2 );

          cmb.Items.Add( 3 );

     

          cmb.SelectedIndex = 1;

     

          cmb.Enabled = true;

          cmb.Visible = true;

     

          cmb.DropDownStyle = ComboBoxStyle.DropDownList;

          cmb.DropDownWidth = 40;

     

          cmb.SelectedIndexChanged += new EventHandler( cmb_SelectedIndexChanged );

     

          e.DataRow.Cells[ “cmbOrden” ].CellViewer = cmb;

          e.DataRow.Cells[ “cmbOrden” ].CellEditor = cmb;

        }

     

        private void cmb_SelectedIndexChanged( object sender, EventArgs e )

        {

          int idx = ( ( Xceed.Grid.Editors.GridComboBox )sender ).SelectedIndex;

     

          Debug.WriteLine( idx.ToString() );

        }

     

     

    Imported from legacy forums. Posted by André (had 664 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Andre. I can’t write before because i was working in another proyect.

     I have tried your example and works, but not in the way i need.

    First, gridControl.AllowCellNavigation must be se to true. Then the combo appears in the cell but only when i click inside it and i need that combo allways visible. What can i do?

     Thanks.

     

    Imported from legacy forums. Posted by Javier (had 369 views)

    User (Old forums)
    Member
    Post count: 23064

    Unfortunately, this is not possible with this version of the grid (2.5).  With version 3.0 and up (and corresponding license key), you could use the CellEditorManager class and set the GridControl.CellEditorDisplayConditions to Always to do this, or simply use a CellViewerManager set to the same control as the CellEditorManager, and it would display the editor.

    Imported from legacy forums. Posted by André (had 3729 views)

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