We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Change column type in the AutoGeneratingColumn event

Hello, 
I want to change a column from text box to combo box and I am trying to do it in the AutoGeneratingColumn event 
with the following code: 

if (e.Column.MappingName.Equals("NameOfColumn")){
     (e.Column as GridComboBoxColumn).DataSource = list, 
}

I get the following error: Object reference not set in An instance of an object.

Thank you

3 Replies

SA Saravanan Ayyanar Syncfusion Team December 23, 2019 12:32 PM UTC

Hi Julio, 
 
Thanks for using Syncfusion control. 
 
You can change the column type from GridTextColumn to GridComboBoxColumn by using AutoGeneratingColumn event in SfDataGrid. We have analyzed your code example. In that, you are trying to type case the GridTextColumn to GridComboBoxColumn, so only you face the exception. You have to create the GridCombBoxColumn as per the below code for achieve your requirement. 
 
Code Snippet: 
private void SfDataGrid1_AutoGeneratingColumn(object sender, Syncfusion.WinForms.DataGrid.Events.AutoGeneratingColumnArgs e) 
{ 
    if (e.Column.MappingName == "Country") 
    { 
        if (e.Column is GridTextColumn) 
        { 
            e.Column = new GridComboBoxColumn() { MappingName = "Country", HeaderText = "Country", DataSource=usStates};     
        } 
    } 
}        
 
Please refer to the sample for the same from the below link 
 
 
 
Please let us know, if you require further assistance on this. 
 
Regards, 
Saravanan A. 



JU Julio January 10, 2020 05:49 PM UTC

Hello

I accomplished what i needed

Thanks for your help.


FP Farjana Parveen Ayubb Syncfusion Team January 13, 2020 05:33 AM UTC

Hi Julio, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Farjana Parveen A 


Loader.
Live Chat Icon For mobile
Up arrow icon