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

Setting datasource for ComboBoxColumn in Grid

4 Answers 770 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dariush Habibi
Top achievements
Rank 1
Dariush Habibi asked on 13 Sep 2012, 10:26 PM
I have added ComboBoxcolumn to the grid, can not see any place to set the datasource for the list of items to populate the list.  The value selected comes from the data source which supplies the whole grid for data.  Have looked every where and can not see how to set the datasource for this column, assuming the selection from the list will be made based on match for the data column.

4 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 14 Sep 2012, 01:43 PM
Hi Dariush,

You can set the datasource of GridViewComboBoxColumn by setting its DataSource property. Your assumption that the selected values will come from the data source which fills the whole RadGridView with data is correct. For additional information about GridViewComboBoxColumn, please refer to our online documentation.

Let me know if you have additional questions.

Greetings,
Nikolay
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Dariush Habibi
Top achievements
Rank 1
answered on 14 Sep 2012, 04:59 PM
Sorry I have seen some code related to setting the data source for the column in code but how about design time.

In property builder I have added a ComboBox column to the list of columns which are there from my stored procedure related data source.  I have another stored procedure and another data source which pulls out the list of the names of sales people for example.  I want this column to show a drop down of all of the sales people and the original stored procedure for the grid has a sales person's name so I want this sales person to be the selection out of this combo box.

I have gone through every field in the Advanced section for the combo box column and don't see where to set the datasource for the column.  In code also when I grab the column and try to call its functions I only see the same list which is in Advanced settings, again no Datasource to set to an existing datasource which is then tied to a stored procedure in the database.  Really like to get all of this working today, thanks.  I am afraid if I do the data source in code then proper selection is not made for each row of data. Again Sales person's name is returned in the stored procedure for the grid, this person needs to be selected in the big list in the combo box.



0
Dariush Habibi
Top achievements
Rank 1
answered on 14 Sep 2012, 08:46 PM
This is not working either.
the stored procedure returns two columns, ID and FullName
Like to show the FullName in the list and again select the name which the grid has for the sales person. 

            GridViewComboBoxColumn SalesPeople = new GridViewComboBoxColumn();
            SalesPeople.Name       = "SalesPeople";
            SalesPeople.HeaderText = "Sales Person";
            SalesPeople.DataSource = ds_tblSalesPeople_GetListWithID;
            SalesPeople.ValueMember = "ID";
            SalesPeople.DisplayMember = "FullName";
            SalesPeople.FieldName = "FullName";
            SalesPeople.Width = 150;
            GRD_Quotes.Columns.Add(SalesPeople);
0
Nikolay
Telerik team
answered on 17 Sep 2012, 09:40 AM
Hello Dariush,

Thank you for writing back.

You should have no concerns setting the DataSource of the column programmatically - this does not have anything to do with the selection of the cells in the column. The selection depends only on the values contained in the data source that is bound to RadGridView. I checked the way you are setting up the GridViewComboBoxColumn and I believe that the issue comes from there.

Simply put, the selection in the column depends on the FieldName and the ValueMember that you set.
The selection values are taken from the column referenced via the FieldName property, but these values should match the ValueMember values of the GridViewComboBoxColumn's datasource. So, let's say that 
you have a datasource bound to RadGridView, and this datasource contains only the IDs of Persons. There is another datasource which contains both the IDs of the FullNames of these persons. So, if you set the FieldName to ID (assuming that this is the name of id column for the persons in the main table) and the ValueMember to ID (assuming that this is the name of id column for the persons in the persons table), the cells in GridViewComboBoxColumn will correctly display the FullName data that corresponds to the ID values.

I hope that this explanation helps. Let me know if you have additional questions.

All the best,
Nikolay
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Dariush Habibi
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Dariush Habibi
Top achievements
Rank 1
Share this question
or