BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
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>
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.
Thank you sir! It's exactly what I wanted.