This is a migrated thread and some comments may be shown as answers.

Set public property with custom FieldSelectorTemplate

1 Answer 24 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Art Kedzierski
Top achievements
Rank 2
Art Kedzierski asked on 19 Jul 2012, 02:41 PM
I have a public property on one of my classes that is configurable by a PropertyGrid. It is a string property, but I want the user to be able to set it from a RadComboBox with values provided from an OpenAccess data model. I can't seem to put all the pieces together. The closest I got puts an odd value in the public property ("Telerik.Windows.Controls.RadComboBoxItem: City, State"). I've been banging my head against this for days and I'm tantalizingly close, but I'm just not seeing something.

How do I connect all the bits? The choices to the data source and the selected item to the public property? Here's my code without all my failed efforts taking up space.


Here's the property:
private string weatherloc;
 
[Category("MissionBoard")]
[Description("Weather station location")]
public string WeatherLoc
{
    get { return weatherloc; }
    private set { weatherloc = value; }
}

Here's the RadComboBox in the DataTemplate:
<Grid.Resources>
    <c:FieldTemplateSelector x:Key="DataTemplateSelector">
        <c:FieldTemplateSelector.WeatherDataTemplate>
            <DataTemplate>
                <telerik:RadComboBox x:Name="WeatherComboBox"
                             Loaded="WeatherComboBox_Loaded" />
            </DataTemplate>
        </c:FieldTemplateSelector.WeatherDataTemplate>
    </c:FieldTemplateSelector>
</Grid.Resources>

And here's the code-behind to (hopefully) populate the control:
private void WeatherComboBox_Loaded(object sender, RoutedEventArgs e)
{
    using (EntitiesModel dbContext = new EntitiesModel())
    {
        try
        {
            var q = (from i in dbContext.WeatherFeeds
                     orderby i.Location
                     select new { i.Location }).ToList();
 
            // How to bind all the bits? The public property to the SelectedItem
                // and the choices to the data source.
        }
        catch (SqlException sx)
        {
            Console.WriteLine(sx.ToString());
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 24 Jul 2012, 02:56 PM
Hi Art,

It should work as it follows: RadComboBox's SelectedItem should be bound to the string property, so that it gets updates when the SelectedItem changes. The EntityCollection should be set as ItemsSource and SelectedValuePath should be set with the name of the property of the model, which value you want to retrieve and set to the bound property. Please, let us know whether you need any additional help with the implementation.

Kind regards,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
PropertyGrid
Asked by
Art Kedzierski
Top achievements
Rank 2
Answers by
Ivan Ivanov
Telerik team
Share this question
or