GridViewComboBoxColumn problem

11 posts, 0 answers
  1. Lovsten
    Lovsten avatar
    72 posts
    Member since:
    Aug 2007

    Posted 04 Sep 2007 Link to this post

    I've got two tabels: Products(Id,Name,SupplierId) and Suppliers(Id,Name). Products har FK to Suppliers.

    I want to list Products in Gridview. I have the tables in Business Objects and set grid.datasource to the objects.

    But instead of showing SupplierId I want to show Supplier.Name. No problem (it's loaded into my BO).

    Then I want to have a combobox for changing the SupplierId on the Product.  The combo should also show Supplier.Name. But when I save the change I want to save supplierId. How can set this up?


  2. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 05 Sep 2007 Link to this post

    Hi Lovsten,

    You should use GridViewComboBoxColumn in the grid for the SupplierId column and set its DataSource, DisplayMember and ValueMember properties (respectively to Suppliers, Suppliers.Name and Suppliers.Id). Please take a look at "Column Types" example of our grid in the installation which demonstrates the usage of such a column.

    If you have any additional questions, please don't hesitate to write us.

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Lovsten
    Lovsten avatar
    72 posts
    Member since:
    Aug 2007

    Posted 06 Sep 2007 Link to this post

    I know about all those members. The problem is that I want to show Name in both the grid and the combo, but then I want to save the Id. If I do as you say, once I select an item in the combo the Id will be returned to the grid, not the Name.
  5. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 06 Sep 2007 Link to this post

    I finally got your idea, Lovsten! This behavior was due to functionality that was not completed. If you have installed the latest release (Q2 2007 Beta) of our controls this problem should not exist any more. Please tell us if you find any inconsistency related to this functionality.
     

    Regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Lovsten
    Lovsten avatar
    72 posts
    Member since:
    Aug 2007

    Posted 10 Sep 2007 Link to this post

    Problem still exist. I can understand why. 
    This is my code:
    ****
                Dim col As GridViewComboBoxColumn = New GridViewComboBoxColumn("supplierRef")
                With col
                    .HeaderText = "Supplier"
                    .HeaderTextAlignment = headerAlignment
                    .ReadOnly = False
                    .TextAlignment = ContentAlignment.MiddleLeft
                    .VisibleInColumnChooser = True
                    .AllowResize = True
                    .DataSource = _suppliers
                    .ValueMember = "supplierId"
                    .DisplayMember = "supplierRef"
                End With

    where
     _suppliers is my collection of Supplier business object,
    ***** 

    Database look like this
     Product    ProductId Int  PK
                    SupplierId Int FK to Supplier
       
     Supplier   SupplierId Int PK
                    SupplierRef nvarchar(50)
    ****
    So to repeat, I want to show the SupplierRef in the grid, but when I save it I want to save the SupplierId. I also want to show SupplierRef in the combo. With this code I get an cast error int to string. I think because when I save the selected value in combo it comes back as the SupplierId to the grid which is set to show SupplierRef.
    Is there a way around this?

  7. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 10 Sep 2007 Link to this post

    Hi Lovsten,

    I assume that you should create GridViewComboBoxColumn with the name of the data field in the Product table:

        Dim col As GridViewComboBoxColumn = New GridViewComboBoxColumn("SupplierId")

    This is due to the fact that the SupplierId field in the Product table is the place where actually the values are saved. I'm almost sure that this will solve the problem.

    Please don't hesitate to ask us if any further questions popup!


    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. Lovsten
    Lovsten avatar
    72 posts
    Member since:
    Aug 2007

    Posted 11 Sep 2007 Link to this post

    Georgi,

    That's not what I want. If I do that, the SupplierId is shown in the grid. I want to show the SupplierRef.
  9. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 13 Sep 2007 Link to this post

    Hello Lovsten,

    Obviously, there is something we are missing, since this is the correct way of setting GridViewComboBoxColumn. We've tested this behavior and can confirm that it is ok in the Q2 2007 Beta release (in the previous versions this functionality was not present). If you're using the Q2 2007 Beta version and experienced such problem, please send us a small sample project so we could investigate it.
     

    All the best,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. Lovsten
    Lovsten avatar
    72 posts
    Member since:
    Aug 2007

    Posted 14 Sep 2007 Link to this post

    The code is already sent in. See my open support ticket.

    You can find this problem under tabs Setup and Products. Column Supplier.

    I am using the Q2 Beta
  11. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 19 Sep 2007 Link to this post

    Hello Lovsten,

    Sorry for the late reply. We are busy putting the finishing touches on a major release.

    Our investigation shows that there should be no basic problems with binding our controls to your business objects.

    We managed to bind a source of Supplier objects with GridViewComboBoxColumn and it behaves as expected. It was necessary only to change one row from the following method:

    Private Sub grdSetUpProductBindTableStyle()     
                Try    
                    With grdSetupProducts     
                        .ShowItemToolTips = True    
                    End With    
                    With grdSetupProducts.MasterGridViewTemplate     
                        .ShowRowHeaderColumn = False    
                        .AutoGenerateColumns = False    
                        .AllowColumnReorder = True    
                        .AllowMultiColumnSorting = True    
                        .AllowAddNewRow = False    
                        .AllowDeleteRow = False    
                        .AllowEditRow = False    
                        .AddNewRowPosition = PinnedRowPosition.Bottom     
                        .EnableFiltering = False    
                        .EnableEditing = False    
                        .EnableSorting = False    
        
                        'Also need suppliers for combo     
                        _suppliers = Suppliers.GetSuppliers(_identity.CompanyId)     
        
                        .Columns.Clear()     
                        .Columns.Add(DefineGridColumnStyleTextbox("productRef""Ref", ContentAlignment.MiddleLeft, False))     
                        .Columns.Add(DefineGridColumnStyleTextbox("productName""Name", ContentAlignment.MiddleLeft, False))     
                        '.Columns.Add(DefineGridColumnStyleCombo(_suppliers, "supplierRef", "supplierId", "supplierRef", "Supplier", ContentAlignment.MiddleLeft, False))    
                        .Columns.Add(DefineGridColumnStyleCombo(_suppliers, "supplierId""supplierId""supplierRef""Supplier", ContentAlignment.MiddleLeft, False))     
                        .Columns.Add(DefineGridColumnStyleTextbox("supplierProductRef""Supp Prod Ref", ContentAlignment.MiddleLeft, False))     
                        .Columns.Add(DefineGridColumnStyleTextbox("unit""Unit", ContentAlignment.MiddleLeft, False))     
                        .Columns.Add(DefineGridColumnStyleTextbox("weightPerCrate""Weight", ContentAlignment.MiddleRight, False))     
                    End With    
        
                Catch ex As Exception     
                    Throw New Exception(ex.GetBaseException.Message.ToString)     
                End Try    
            End Sub    
     


    Your sample project (or maybe it is not) is quite large, which made it very difficult for us to reveal the reason for the problem. We suggest checking the data your business objects are supplied with.

    If you continue to experience the same problem, please send us a much simpler project which clearly demostrates the problem.

    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  12. Lovsten
    Lovsten avatar
    72 posts
    Member since:
    Aug 2007

    Posted 20 Sep 2007 Link to this post

    Ok. Can't get it to work. But I've done a workaround that works for me.
Back to Top
UI for WinForms is Visual Studio 2017 Ready