Home Forums WinForms controls Xceed Grid for WinForms trouble using GridComboBox as CellViewer

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

    Hi,

    I wanted to use the xceed GridComboBox as a cellviewer in my detail grids. But the statement

    detail.Columns[0].CellViewer = new GridComboBox();

    doesnt have any effect.

    If I use the ControlViewer class like in

    detail.Columns[0].CellViewer =new ControlViewer(new ComboBox(),”Text”); or
    detail.Columns[0].CellViewer =new ControlViewer(new GridComboBox(),”Text”);

    The combobox is displayed as a viewer but it is not painted correctly. The value of the cells is not displayed in the combobox. and the background is totally black in the second case

    does any body have any idea what the problem is?

    Imported from legacy forums. Posted by userX (had 12229 views)

    User (Old forums)
    Member
    Post count: 23064

    You’ll have to bind the GridComboBox to a DataSource, and set the DisplayMember and ValueMember, like this:<code>GridComboBox combo = new GridComboBox();
    combo.DataSource = ds;
    combo.DisplayMember = “X”;
    combo.ValueMember = “Y”;
    detail.Columns[0].CellViewer = combo;</code>DisplayMember is the name of the field that is displayed by the viewer, ValueMember is the name of the field that represents the value of the Cell.

    Imported from legacy forums. Posted by Tommy (had 116 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Tommy,

    Thanks a lot for your reply.
    I tried what you said but i still cant see the viewer, but the editor which is also a GridComboBox is working fine. Here is the what i have,

    I want the items in the editor combobox to vary for each cell. therefore i am using the cell.EnteringEdit event to add each item indivdually to a class level GridCombox, _gridEditor.Items.Add(“”)

    for the viewer i didnt now that i had to supply the datasource but now i tried building a dataset containing all possible items but it still didnt see any viewer.

    I want the combox to apear on the cell before the user click on a cell otherwise the user will not have any idea if he can modify that column.

    any idea?

    Imported from legacy forums. Posted by userX (had 423 views)

    User (Old forums)
    Member
    Post count: 23064

    The CellViewer is used all the time, every time the cell has to be painted.
    Could you give more details what you are trying to do?
    What kind of values are in the cells? How should they be displayed?

    Imported from legacy forums. Posted by Tommy (had 112 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi tommy, here is the code i have

    I would like to show a combobox in each cell. and here is the code i have now.

    _gridDataSet = GetDataSet();
    gridControlOrder.BeginInit();
    gridControlOrder.DataSource=_gridDataSet;
    gridControlOrder.DataMember=”Orders”;

    DetailGrid detail = new DetailGrid();
    detail.HeaderRows.Add( new ColumnManagerRow() );
    detail.DataSource = _gridDataSet;
    detail.DataMember = “Orders.OrdersItems”;
    gridControlOrder.DetailGridTemplates.Clear();
    gridControlOrder.DetailGridTemplates.Add( detail );
    detail.Columns[0].ReadOnly=false;

    _gridEditor = new GridComboBox();
    detail.Columns[0].CellEditor= _gridEditor;

    _gridViewer = new GridComboBox();

    DataTable dt = new DataTable();
    dt.Columns.Add(“display”);
    dt.Columns.Add(“valuemember”);

    System.Data.DataRow dr = dt.NewRow();
    dr[0] = Context.GetResourceString(“TypeOne”);
    dr[1]= Context.GetResourceString(“TypeTOneValue”);
    dt.Rows.Add(dr);

    dr[0] = Context.GetResourceString(“TypeTwo”);
    dr[1]= Context.GetResourceString(“TypeTwoValue”);
    dt.Rows.Add(dr);

    _gridViewerbox = new GridComboBox();
    _gridViewerbox.DataSource = dt;
    _gridViewerbox.DisplayMember = “display”;
    _gridViewerbox.ValueMember = “valuemember”;

    detail.Columns[0].CellViewer = _gridViewerbox;

    foreach(Cell cell in detail.DataRowTemplate.Cells)
    {
    if (cell.ParentColumn.Index==0)
    cell.EnteringEdit += new EnteringEditEventHandler( this.cell_EnteringEdit );
    }

    gridControlOrder.EndInit();

    * on the cell.enteringEdit event. I populate the _gridEditor combobox with the value i want depending on the selected cell.

    — the editing is working fine, but i dont see any comboboxes when the form is displayed intailly.

    thanks!

    Imported from legacy forums. Posted by userX (had 423 views)

    User (Old forums)
    Member
    Post count: 23064

    Make sure that the <b>valuemember</b> column of dt is of the same type as the column in the detailgrid. I have seen this problem before: if the detailgrid column is of type String, and the combobox valuemember column is of type Int32, it won’t display.

    Imported from legacy forums. Posted by Tommy (had 224 views)

    User (Old forums)
    Member
    Post count: 23064

    they are all strings. i tried specifing the data type in the grid too. 🙁

    by the way, even the following statement does not work.
    detail.Columns[0].CellViewer = new ControlViewer(new TextBox(),”Text”);
    the cell value will be empty if i use the above statement.

    i was wondering if there is any property you have to set, or method you have to call to enable the cellviewer functionality.

    anyway, thanks a lot.

    Imported from legacy forums. Posted by userX (had 314 views)

    User (Old forums)
    Member
    Post count: 23064

    Is the value of the cell displayed, if you don’t set the CellViewer?

    Imported from legacy forums. Posted by Tommy (had 370 views)

    User (Old forums)
    Member
    Post count: 23064

    yes the value of the cell is diplayed.

    (but not in the case of cellviewer = new controlviewer(….. )

    Imported from legacy forums. Posted by userX (had 274 views)

    User (Old forums)
    Member
    Post count: 23064

    Then I’m sorry, but I can’t see what the problem is. It might be a good idea to contact Xceed Support: support@xceedsoft.com

    Imported from legacy forums. Posted by Tommy (had 286 views)

    User (Old forums)
    Member
    Post count: 23064

    Try to use the DataGrid.UpdateDetailGrids() method.

    This solve my problem to display a combobox with a description rather than ID for Detail Grids.

    It seems that you need to use this method for any change in DetailGrid template.

    Imported from legacy forums. Posted by ctenuta (had 584 views)

    User (Old forums)
    Member
    Post count: 23064

    I can’t see why you want to use the ComboBox as a CellViewer anyway, as it’s an editor. Used as a viewer it doesn’t look any different from a normal cell – I’m actually surprised it lets you assign it as a viewer!

    Imported from legacy forums. Posted by Duncan (had 997 views)

    User (Old forums)
    Member
    Post count: 23064

    The reason you would use a ComboBox as a CellViewer, is if you don’t want to display the actual value of the cell, but a mapped value.
    Example: you have a column where the values are IDs of employees. You don’t want to display an employee’s ID, but the name of the employee with that ID.
    The ComboBox is bound to a DataTable with employee-data, where the ID-column is the <i>ValueMember</i> of the ComboBox, and the Name-column is the <i>DisplayMember</i> of the ComboBox.
    If you use such a GridComboBox as CellViewer of a column, and that column contains employee IDs, the GridComboBox will display the corresponding Names of those IDs.

    Imported from legacy forums. Posted by Tommy (had 302 views)

    User (Old forums)
    Member
    Post count: 23064

    Duncan: UserX was pretty clear on why he wanted on show the combo box all the time

    quote ‘I want the combox to apear on the cell before the user click on a cell otherwise the user will not have any idea if he can modify that column. ‘

    It’s an userbility issue. I have the same problem in an application I am working on which has has only one cell that is editable. By default its not intutative as to which cell is editable.

    I would prefer to have the combo displayed in each row all the time if the user has update permission and for the combo to be hidden if the user has readonly access to the data.

    i have tried everything I can think of and i have tralwed throught the doco and sample apps.

    Any help would be appreciated.

    Cheers
    Adam

    Imported from legacy forums. Posted by RayMartinsHair (had 654 views)

    User (Old forums)
    Member
    Post count: 23064

    Adam,

    I filed this problem with xceed support back in 2005 and it is working now.
    Here is the reply,

    “The implementation of the ICellViewer interface on the gridComboBox makes it paint only the display member in the cell instead of drawing the whole control.

    If you want to always see the dropdown arrow event when the cells is not being edited, you will have to wrap your gridComboBox inside a ControlViewer.”

    And that will be like,

    GridComboBox _gridViewer = new GridComboBox();
    detail.Columns[0].CellViewer = new ControlViewer(_gridViewer,”Text”);

    cheers

    Imported from legacy forums. Posted by userX (had 527 views)

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