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

How can i get Text of GridComboBoxColumn?

Hello, I have a GridComboBoxColumn with IsEditable set to true and I want to handle the entered text.


XAML:


<syncfusion:SfDataGrid

x:Name="LessonsDataGrid"

AddNewRowPosition="Bottom"

AllowEditing="True"

EditTrigger="OnDoubleTap"

ItemsSource="{Binding EmployeeLessons}"

NavigationMode="Cell"

SelectionMode="Extended">

<syncfusion:SfDataGrid.Columns>


<syncfusion:GridComboBoxColumn

DisplayMemberPath="Lesson"

HeaderText="Lesson"

IsEditable="True"

ItemsSource="{Binding Lessons}"

MappingName="Lesson"

SelectedValuePath="Lesson" />


<syncfusion:GridComboBoxColumn

DisplayMemberPath="Level"

HeaderText="Level"

IsEditable="True"

ItemsSource="{Binding Levels}"

MappingName="Level"

SelectedValuePath="Level" />


<syncfusion:GridComboBoxColumn

DisplayMemberPath="Class"

HeaderText="Class"

IsEditable="True"

ItemsSource="{Binding Classes}"

MappingName="Class"

SelectedValuePath="Class" />


</syncfusion:SfDataGrid.Columns>

</syncfusion:SfDataGrid>



2 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team February 9, 2023 02:21 PM UTC

Hi Diyari,

Your requirement to get text of GridComboBoxColumn in SfDataGrid can be achieved by overriding the OnEditElementLoaded method in GridCellComboBoxRenderer and customize the TextChanged event. Refer to the below code snippet,

//Remove existing ComboBox Renderer

LessonsDataGrid.CellRenderers.Remove("ComboBox");

//Add customized ComboBox Renderer

LessonsDataGrid.CellRenderers.Add("ComboBox", new GridCellComboBoxRendererExt());

//GridCellComboBoxRenderer customization

public class GridCellComboBoxRendererExt : GridCellComboBoxRenderer

{

    protected override void OnEditElementLoaded(object sender, RoutedEventArgs e)

    {

        base.OnEditElementLoaded(sender, e);

        var combobox = ((ComboBox)sender);

        if (combobox != null)

        {

            TextBox comboTextBox = (TextBox)GridUtil.FindDescendantChildByType(combobox, typeof(TextBox));

            if (comboTextBox != null)

                //Event subscription

                comboTextBox.TextChanged += OnComboTextBoxTextChanged;

        }

    }

 

    //Event customization

    private void OnComboTextBoxTextChanged(object sender, TextChangedEventArgs e)

    {

        //Here get the TextBox

        var textBox = (e.OriginalSource as TextBox);

 

        if(textBox != null)

        {

            //Here get the entered text in ComboBox when editing

            var text = textBox.Text;

            Console.WriteLine("Get EnteredText is : " + text);

        }

    }

}


UG Link: https://help.syncfusion.com/wpf/datagrid/column-types#customize-column-renderer

https://help.syncfusion.com/wpf/datagrid/column-types#gridcomboboxcolumn

Find the sample in the attachment.


Regards,

Vijayarasan S


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: Sample_d5e433f.zip

Marked as answer

DI Diyari replied to Vijayarasan Sivanandham February 9, 2023 03:27 PM UTC

Thank you sir! It's exactly what I wanted.


Loader.
Live Chat Icon For mobile
Up arrow icon