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 to add a control to a "property box"

My PropertyGrid displays many string variables which are paths to files and folders,


I wouldn't want someone to edit them manually in textBox


is it possible to (set the read-only property field and) add a button "..." exactly the same as it appears in the Collection type


Like this:

propertyGrid.png


3 Replies 1 reply marked as answer

GT Gokul Thanudhas Syncfusion Team November 8, 2022 05:56 PM UTC

Hi Mateusz,


You can able to achieve your requirement using the custom editor . We have created the simple sample based on your requirement. Please refer the sample for your reference.


Regards,

Gokul T


Attachment: PropertyGrid_50bf62dc.zip

Marked as answer

MA Mateusz November 9, 2022 07:39 AM UTC

hello Gokul,

thank you so much for your help!

meanwhile I managed to read about custom editor and solved that by creating my BrowseFolderEditor,

your solution seems more elegant to me :)

my code:


public class BrowseFolderEditor : ITypeEditor
{
private Grid browseGrid;
private TextBox browseTextBox;
private Button browseButton;

public void Attach(PropertyViewItem property, PropertyItem info)
{
var binding = new Binding("Value")
{
Mode = BindingMode.TwoWay,
Source = info,
ValidatesOnExceptions = true,
ValidatesOnDataErrors = true
};

BindingOperations.SetBinding(browseTextBox, TextBox.TextProperty, binding);
}

public object Create(PropertyInfo propertyInfo)
{
browseGrid = new Grid();

var gridCol1 = new ColumnDefinition
{
Width = new GridLength(1, GridUnitType.Star)
};
browseGrid.ColumnDefinitions.Add(gridCol1);

var gridCol2 = new ColumnDefinition
{
Width = new GridLength(50, GridUnitType.Pixel)
};
browseGrid.ColumnDefinitions.Add(gridCol2);

browseTextBox = new TextBox()
{
IsReadOnly = true,
BorderThickness = new Thickness(0),
VerticalContentAlignment = VerticalAlignment.Center,
};
Grid.SetColumn(browseTextBox, 0);

browseButton = new Button
{
Content = "...",
};
browseButton.Click += BrowseFolder;
Grid.SetColumn(browseButton, 1);

browseGrid.Children.Add(browseTextBox);
browseGrid.Children.Add(browseButton);

return browseGrid;
}

public void Detach(PropertyViewItem property)
{
browseGrid = null;
browseTextBox = null;
browseButton = null;
}

private void BrowseFolder(object sender, RoutedEventArgs e)
{
using (var fbd = new FolderBrowserDialog())
{
var result = fbd.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{
browseTextBox.Text = fbd.SelectedPath;
browseTextBox.Focus(); //focus to refresh the value
}
}
}
}​


GT Gokul Thanudhas Syncfusion Team November 9, 2022 02:16 PM UTC

We are glad to know that your issue has been fixed. Please let us know if you need any other assistance. We are happy to assist you.

Loader.
Live Chat Icon For mobile
Up arrow icon