Change Column Type

Once I assign a data source to the grid I get following



How do I change the first column from a GridTextColumn to a GridComboBoxColumn and then assign it to a data source for the drop down list?  I used to be able to change it within the properties of the column, can I still do that and if so where?

I noticed that I can manually add a column and when doing so choose the type of column that I want.  When I choose GridComboBoxColumn I get the follown



This seems to work without issue until I click on the cell of an item to see the combo box drop down list and then I get the following error



My data source is Microsoft's standard databinding source.  Am I missing a setting to allow the combo box to show?


thanks

11 Replies

FP Farjana Parveen Ayubb Syncfusion Team July 26, 2018 11:49 AM UTC

Hi Derek, 
 
Thanks for contacting Syncfusion support. 
 
The GridComboBoxColumn should be added manually as like the below code example or designer as you tried. 
 
Code Example   
 
this.sfDataGrid1.Columns.Add(new GridComboBoxColumn() { MappingName = "ShipCityID", HeaderText = "Ship City", DisplayMember = "ShipCityName", ValueMember = "ShipCityID", DropDownStyle = DropDownStyle.DropDownList, DataSource = bindingSource.DataSource }); 
 
Currently we don’t have BindingSource support for GridComboBoxColumn. This will be available in our 2018 Volume 3 release. But you can set the BindingSource.DataSource for DataSource property in GridComboBoxColumn programmatically. Please refer the below code example, 
 
Code Example   
 
this.sfDataGrid1.Columns.Add(new GridComboBoxColumn() { MappingName = "ShipCityID", HeaderText = "Ship City", DisplayMember = "ShipCityName", ValueMember = "ShipCityID", DropDownStyle = DropDownStyle.DropDownList, DataSource = bindingSource.DataSource }); 
 
Note: Currently we don’t have a DataTable binding support for GridComboBoxColumn. This feature also will be available in our upcoming 2018 Volume 3 release. 
 
  
Regards, 
Farjana Parveen A 
 



DG Derek Geldart August 3, 2018 01:41 PM UTC

I tried the following line of code as you suggested

gridPipe.Columns.Add(New GridComboBoxColumn() With {.MappingName = "SalesType", .HeaderText = "Sales Type", .ValueMember = "SalesType", .DisplayMember = "SalesType", .DataSource = _20SalesTypeBindingSource.DataSource})

I am still getting the following error whenever I double click on the cell of this comboboxcolumn



What piece of code am I missing?


MA Mohanram Anbukkarasu Syncfusion Team August 6, 2018 11:33 AM UTC

Hi Derek,   
  
Thanks for your update.   
  
There is no error in the provided code to add the GridComboBoxColumn column. It is hard for us to trace why this issue is arising without having a look at your sample.   
  
Could you please provide the exact stack trace of the exception or point out to us the difference between our provided sample and your application? Also, provide the details about the DataSource type which you have assigned to ComboBox column. We have already updated that ComboBox column won’t support the DataTable type. If you provide the requested details, we could sort out the cause for the issue and provide you an exact solution.   
  
  
Regards,   
Mohanram A.   



DG Derek Geldart August 7, 2018 07:26 PM UTC

Can you please send me the above sample in vb.net?  Does the Combobox support an array and if so what would the code look like to add a combobox column with an array as a datasource?




MA Mohanram Anbukkarasu Syncfusion Team August 8, 2018 12:05 PM UTC

Hi Derek, 
  
Thanks for your update. 
  
Please find the VB sample from the below location. 
  
  
Since GridComboBoxColumn support only IEnumerable DataSources, it doesn’t support an array as DataSource. Instead of using array you can use ObservableCollection as given in the above sample. Please let us know if you have any other queries. 
  
Please refer to the UG link for the data binding of SfComboBox. 
  
  
Regards, 
Mohanram A. 



DG Derek Geldart August 8, 2018 08:20 PM UTC

I took the sample code that you provided me in the sample project as a template and came up with the following

 Dim bindingSource As New BindingSource()
            Dim orderInfo As New LoadComboData
            bindingSource.DataSource = orderInfo.SalesTypes
            Me.gridPipe.Columns.Add(New GridComboBoxColumn() With {.MappingName = "SalesType", .HeaderText = "Sales Types", .DisplayMember = "SalesType", .ValueMember = "SalesTypes", .DropDownStyle = DropDownStyle.DropDownList, .DataSource = bindingSource.DataSource})


Public Class SalesTypes

    Implements INotifyPropertyChanged
    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    Private Sub RaisePropertyChanged(ByVal name As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
    End Sub

    Private SalesLocations As String

    Public Property SalesTypes As String

        Get
            Return SalesLocations
        End Get
        Set(ByVal value As String)
            SalesLocations = value
            RaisePropertyChanged("SalesType")
        End Set
    End Property

End Class



Public Class LoadComboData

    Implements IDisposable
    Public Sub New()
        Dim shipCityDetails As New ObservableCollection(Of SalesTypes)()
        shipCityDetails.Add(New SalesTypes() With {.SalesTypes = "UNITED STATES"})
        shipCityDetails.Add(New SalesTypes() With {.SalesTypes = "LOCAL"})
        shipCityDetails.Add(New SalesTypes() With {.SalesTypes = "SPALDING"})
        Me.SalesTypes = shipCityDetails
    End Sub


    Private privateSalesTypes As ObservableCollection(Of SalesTypes)


    Public Property SalesTypes() As ObservableCollection(Of SalesTypes)
        Get
            Return privateSalesTypes
        End Get
        Set(ByVal value As ObservableCollection(Of SalesTypes))
            privateSalesTypes = value
        End Set
    End Property



    Public Sub Dispose() Implements IDisposable.Dispose
        Dispose()
        GC.SuppressFinalize(Me)
    End Sub
End Class



When I run the program it adds the column and has the correct data showing in the grid.  However, when I double click on the cell the combobox does not show but instead shows the same error as before.  The only difference that I can see between the sample and my code is that in my grid I connect to a data table for all columns except the combobox and then add it manually.  If there is no current solution for this problem will release 3 have this issue fixed so that I can bind a combobox to my original datasource table, just like the checkbox column?

Thanks




FP Farjana Parveen Ayubb Syncfusion Team August 9, 2018 01:02 PM UTC

Hi Derek, 
 
Sorry for the inconvenience caused. 
 
We have analyzed your code provided in the last updated. You have set the DisplayMember for GridComboBoxColumn as “SalesType” but that property is not available in the ComboBoxCollection(ObservableCollection(Of SalesTypes)) which is bounded to GridComboBoxColumn. So, the ComboBox is not loaded while trying to double click on cell. You should set the DisplayMember property which is available in the ComboBoxCollection. Here we have provided the sample like your code. Please make use of the below code, 
 
Please refer the below code example 
 
Code Example: 
sfDataGrid.Columns.Add(New GridComboBoxColumn() With {.MappingName = "SalesType", .HeaderText = "Sales Types", .DisplayMember = "SalesType", .ValueMember = "SalesType", .DropDownStyle = Syncfusion.WinForms.ListView.Enums.DropDownStyle.DropDownList, .DataSource = bindingSource.DataSource}) 
 
 
 
Regards, 
Farjana Parveen A  



DG Derek Geldart August 9, 2018 05:30 PM UTC

I want to begin by saying thanks for this solution works really well.  I can add the coboboxcolumn and it is capable of doing the following:

1.  show the data from the dataset
2.  drop down and show the list of items when double clicking on the cell
3.  place the item in the cell once chosen
4.  update the dataset and table behind it

The only issue I have left is that I set the datasource for the grid manually before I run the program.  I do this so that I can setup my columns in the exact order and with the styles that I prefer.  If I run the code that you sent me using my dataset the program doubles the column "SalesType."  If I remove the datasource from the grid and its associated columns and add the dataset as the datasource of the grid at runtime, the program only shows one column and the comboboxcolumn works perfectly but the data from the dataset does not display data in the column.  Is there a way around this or am I to hide the original "SalesType"column (the one generated when I set the datasource of the grid manually) and then move the new combobox column beside it?  If so what is the code to move a column's position in the grid so that instead of showing up in the last column of the grid it shows up as the second column of the grid?

I thank you in advance for your help.


FP Farjana Parveen Ayubb Syncfusion Team August 10, 2018 11:34 AM UTC

Hi Derek, 
 
Thanks for your updated. 
 
Is there a way around this or am I to hide the original "SalesType"column (the one generated when I set the datasource of the grid manually) 
You can skip a column from being auto generated by using AutoGeneratingColumn event. Please refer the below code example 
 
Code Example 
 
AddHandler sfDataGrid.AutoGeneratingColumn, AddressOf sfDataGrid_AutoGeneratingColumn 
 
Private Sub sfDataGrid_AutoGeneratingColumn(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.AutoGeneratingColumnArgs) 
       If e.Column.MappingName = "SalesType" Then 
              e.Cancel = True 
       End If 
End Sub 
 
What is the code to move a column's position in the grid so that instead of showing up in the last column of the grid it shows up as the second column of the grid? 
You can insert GridComboBoxColumn as second column by using Insert method. Please refer the below code example 
 
Code Example 
 
 
sfDataGrid.Columns.Insert(1, New GridComboBoxColumn() With {.MappingName = "SalesType", .HeaderText = "Sales Types", .DisplayMember = "SalesType", .ValueMember = "SalesType", .DropDownStyle = Syncfusion.WinForms.ListView.Enums.DropDownStyle.DropDownList, .DataSource = bindingSource.DataSource}) 
 
 
  
Regards, 
Farjana Parveen A 



DG Derek Geldart August 10, 2018 05:35 PM UTC

Thank you, the provided code worked very well.  Just two more questions

1.  Is there a way to create a two column combobox with one column containing an abbreviation for an item and the second a longer name and add it to the sfdatagrid?
2.  Will the release 3 have BindingSource support for GridComboBoxColumn?

Again, thanks for the help


NK Neelakandan Kannan Syncfusion Team August 13, 2018 07:35 AM UTC

Hi Derek, 
 
Thanks for your update. 
 
Is there a way to create a two column combobox with one column containing an abbreviation for an item and the second a longer name and add it to the sfdatagrid? 
Currently we don’t have support for GridMultiColumnComboBoxColumn in SfDataGrid. We have added this feature to our feature request list. It will be available in any of our upcoming releases. 
Will the release 3 have BindingSource support for GridComboBoxColumn? 
Yes. BindingSource support for GrodComboBoxColumn will be available in our 2018 Volume 3 release which is expected to be rolled out in Mid of September (2018) 
 
Regards, 
Neelakandan 
 


Loader.
Up arrow icon