This is a migrated thread and some comments may be shown as answers.

GridViewComboBoxColumn problem

10 Answers 269 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lovsten
Top achievements
Rank 1
Lovsten asked on 04 Sep 2007, 11:01 AM
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?


10 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 05 Sep 2007, 04:39 PM
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
0
Lovsten
Top achievements
Rank 1
answered on 06 Sep 2007, 07:29 AM
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.
0
Georgi
Telerik team
answered on 06 Sep 2007, 01:32 PM
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
0
Lovsten
Top achievements
Rank 1
answered on 10 Sep 2007, 09:03 AM

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?

0
Georgi
Telerik team
answered on 10 Sep 2007, 05:01 PM
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
0
Lovsten
Top achievements
Rank 1
answered on 11 Sep 2007, 05:46 AM
Georgi,

That's not what I want. If I do that, the SupplierId is shown in the grid. I want to show the SupplierRef.
0
Georgi
Telerik team
answered on 13 Sep 2007, 04:50 PM
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
0
Lovsten
Top achievements
Rank 1
answered on 14 Sep 2007, 05:55 AM
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
0
Georgi
Telerik team
answered on 19 Sep 2007, 02:25 PM
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
0
Lovsten
Top achievements
Rank 1
answered on 20 Sep 2007, 07:03 AM
Ok. Can't get it to work. But I've done a workaround that works for me.
Tags
GridView
Asked by
Lovsten
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Lovsten
Top achievements
Rank 1
Share this question
or