GridComboBoxColumn How to set default Display Text?

I have looked all through the Properties for the GridComboBoxColumn.  I cannot find a "DefaultDisplayText" when there is no matching Value.  This is for whne there is a new row when there is no link to the Row yet.  I would like to say "Select item" when there is no selected ComboBox value.

Anybody know how to do this?  

Thanks in advance.

5 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team September 29, 2020 01:42 PM UTC

Hi Robert, 

Thanks for contacting Syncfusion support.  

GridComboBoxColumn diesn;t have any direct support to display default text on it when there is no selected item. However you can achieve this requirement by using SfDataGrid.DrawCell event as shown in the following code example. 

Code example :  

this.sfDataGrid.DrawCell += SfDataGrid_DrawCell; 
 
private void SfDataGrid_DrawCell(object sender, Syncfusion.WinForms.DataGrid.Events.DrawCellEventArgs e) 
{ 
    if(e.Column.MappingName == "ShipCountry" && string.IsNullOrEmpty(e.DisplayText)) 
    { 
        e.Style.TextColor = Color.Gray; 
        e.DisplayText = "Select Item"; 
    } 
} 

 



Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 



RO Robert September 29, 2020 02:48 PM UTC

Hi,  Thanks for the reply.  But the code did not work.  There is no SFDataGrid.DrawCell event. Your answer appears to be for WinForms.  I am using UWP.  Any other suggestions?


MA Mohanram Anbukkarasu Syncfusion Team September 29, 2020 03:54 PM UTC

Hi Robert, 

Sorry for the inconvenience.  

You can achieve this requirement in UWP using DisplayBinding property of the column as shown in the following code example. 

Code example :  

<Page.Resources> 
    <local:ComboBoxValueConverter x:Key="comboBoxValueConverter"/> 
</Page.Resources> 
 
<syncfusion:GridComboBoxColumn MappingName="ReportsTo" ItemsSource="{Binding Reporters}" DisplayBinding="{Binding Path=ReportsTo, Converter={StaticResource comboBoxValueConverter}}"/> 
 
public class ComboBoxValueConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, string language) 
    { 
        if (string.IsNullOrEmpty(value.ToString())) 
            value = "Select a Value"; 
        return value; 
    } 
 
    public object ConvertBack(object value, Type targetType, object parameter, string language) 
    { 
        throw new NotImplementedException(); 
    } 
} 



Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 




Marked as answer

RO Robert September 29, 2020 04:10 PM UTC

Thanks for that.  That worked fine.


MA Mohanram Anbukkarasu Syncfusion Team September 30, 2020 05:16 AM UTC

Hi Robert,  

Thanks for the update.  

We are glad to know that the provided solution worked at your end. Please let us know if you have any further queries on this. We are happy to help you. 

Regards, 
Mohanram A. 


Loader.
Up arrow icon