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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Change column type in the AutoGeneratingColumn event

Thread ID:





150118 Dec 20,2019 10:42 PM UTC Jan 13,2020 05:33 AM UTC WinForms 3
Tags: SfDataGrid
Asked On December 20, 2019 10:42 PM UTC

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

Saravanan Ayyanar [Syncfusion]
Replied On 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. 
Saravanan A. 

Replied On January 10, 2020 05:49 PM UTC


I accomplished what i needed

Thanks for your help.

Farjana Parveen Ayubb [Syncfusion]
Replied On 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. 
Farjana Parveen A 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon