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
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
Regards,
Georgi
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
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?
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
That's not what I want. If I do that, the SupplierId is shown in the grid. I want to show the SupplierRef.
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
You can find this problem under tabs Setup and Products. Column Supplier.
I am using the Q2 Beta
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