ComboBox Resets Value / IsEditable & ItemsSource
Syncfusion 28.2.6
Hello,
I have a problem with the AdvCombobox.
The combobox is dynamically created in the PropertyGrid with an ItemsSource and the following parameters:
IsEditable = true,
AutoCompleteMode = AutoCompleteModes.None,
IsTextSearchEnabled = true
However, when a user enters their own value, it always gets overwritten by the templates.
Is there a solution for this?
The zip file contains a video.
Best regards
<---- Code --->
namespace RRX.Propertygrid
{
public class CustomDropDownEditor : BaseTypeEditor
{
private DockPanel panel;
private Button button;
private Image icon;
private ComboBoxAdv combo;
public override void Attach(PropertyViewItem property, PropertyItem info)
{
if (combo == null)
return;
// Setze dynamisch die ItemsSource basierend auf dem Namen des Objekts
SetItems(info.Name);
SetIcon(info.Description);
// Binding erstellen und setzen
var binding = base.CreatePropertyInfoBinding(info, combo);
BindingOperations.SetBinding(combo, ComboBoxAdv.TextProperty, binding);
// Initialisiere den Wert der ComboBox basierend auf der aktuellen Info
if (info.Value != null)
{
combo.Text = info.Value.ToString();
}
}
public override object Create(PropertyInfo propertyInfo)
{
panel = new DockPanel();
panel.Children.Add(this.CreateButton());
panel.Children.Add(this.CreateCombo());
panel.Focusable = true;
panel.GotFocus += Combo_GotFocus;
return panel;
}
public override object Create(PropertyDescriptor propertyDescriptor)
{
panel = new DockPanel();
panel.Children.Add(this.CreateButton());
panel.Children.Add(this.CreateCombo());
return panel;
}
public override void Detach(PropertyViewItem property)
{
if (combo != null)
{
//BindingOperations.ClearAllBindings(combo);
combo.ItemsSource = null;
combo.Items.Clear();
combo = null;
}
panel = null;
button = null;
}
public override bool ShouldPropertyGridTryToHandleKeyDown(Key key)
{
return false;
}
private Button CreateButton()
{
// Set a small icon for the button
icon = new Image();
icon.Stretch = Stretch.Fill;
icon.Height = 15;
button = new Button
{
Margin = new Thickness(1),
ToolTip = "",
Width = 17,
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Center,
BorderThickness = new Thickness(0),
Background = Brushes.Transparent,
Content = icon,
};
return button;
}
private ComboBoxAdv CreateCombo()
{
combo = new ComboBoxAdv
{
BorderThickness = new Thickness(0),
HorizontalAlignment = HorizontalAlignment.Stretch,
Height = 17,
Margin = new Thickness(0),
IsEditable = true,
AutoCompleteMode = AutoCompleteModes.None,
IsTextSearchEnabled = true,
};
DockPanel.SetDock(combo, Dock.Right);
return combo;
}
private void Combo_GotFocus(object sender, RoutedEventArgs e)
{
// Ensure sender is a ComboBox
if (sender is ComboBoxAdv focusedCombo)
{
// Perform actions when ComboBox gains focus
MessageBox.Show($"ComboBox '{focusedCombo.Name}' has gained focus!");
// Example: Update ItemsSource dynamically or perform other operations
SetItems("DynamicUpdate"); // Replace with your logic
}
}
private void SetIcon(string objectDescription)
{
switch (objectDescription)
{
case "Key":
icon.Source = PropertygridIconSerializer.IconKey();
break;
case "Label":
icon.Source = PropertygridIconSerializer.IconLabel();
break;
case "Mark":
icon.Source = PropertygridIconSerializer.IconMark();
break;
case "Override":
icon.Source = PropertygridIconSerializer.IconOverride();
break;
case "Counter":
icon.Source = PropertygridIconSerializer.IconCounter();
break;
default:
break;
}
}
private void SetItems(string objectName)
{
if (G_CacheResources.G != null)
{
switch (objectName)
{
case "ComponentKey":
combo.ItemsSource = G_CacheResources.G.xItemResourceDrop.ComponentKey;
combo.DisplayMemberPath = "Equal";
default:
break;
}
if (combo.Items.Count == 0)
{
combo.Items.Add("");
}
}
}
}
}
Attachment: ComboBox_Value_Reset_26d468f3.zip
Hi Matthias,
We have validated your query and have determined that the issue arises due to the IsTextSearchEnabled property being set to true, which causes the user's input to be replaced automatically.
To address this, please set IsTextSearchEnabled to false. This adjustment will enable users to input their own values without being overwritten by the predefined template.
Let us know if you need further assistance.
Regards,
Nithi Sneha S
- 1 Reply
- 2 Participants
-
MW Matthias Wieland
- Feb 24, 2025 01:15 PM UTC
- Feb 25, 2025 07:32 AM UTC