Select to view content in your preferred language

populating ProWindow combo box control with values at load or show

184
1
Jump to solution
06-20-2024 10:40 AM
SteveCole
Frequent Contributor

Now diving into the Pro SDK after so much time in the VBA & even VB.NET add-in sphere and I'm struggling with how to accomplish a specific task. I'm sure these are growing pains with C# but the Pro SDK isn't really doing me any favors about this either.

I have a ProWindow which prompts the user to provide input parameters for tweaking the color ramp of a raster in the TOC. What I would like to do is populate a combo box with a list of the rasters in the TOC. I have the code to retrieve a list of rasters in the map:

 

var layerlist = MapView.Active.Map.GetLayersAsFlattenedList().OfType<BasicRasterLayer>();

 

 

but what I cannot figure out is how to insert this list of layers into the combo box. I've figured out how to find the event associated with the control but the process of how to populate it's data source is lost on me:

 

        private void cboLayerList_Loaded(object sender, RoutedEventArgs e)
        {
            var layerlist = MapView.Active.Map.GetLayersAsFlattenedList().OfType<BasicRasterLayer>();
            
        }

 

 

My control's name (cboLayerList) doesn't appear in the Intellisense suggestions so I'm at a loss as to how to hook into the control to populate the list of layers. There is a community sample about a combo box showing layers but I can't make the connection between that sample and how I'm trying to populate a combo box in my ProWindow.

What am I missing (besides an understanding of C#)?

Steve

0 Kudos
1 Solution

Accepted Solutions
SteveCole
Frequent Contributor

In answer to my own question, my Googling finally brought forth a solution that worked for referencing the control. Here's how I have implemented it:

        private void cboLayerList_Loaded(object sender, RoutedEventArgs e)
        {
            var layerlist = MapView.Active.Map.GetLayersAsFlattenedList().OfType<BasicRasterLayer>();
            var theCombobox = (System.Windows.Controls.ComboBox)this.FindName("cboLayerList");

            theCombobox.Items.Clear();

            foreach (var layer in layerlist) {
                theCombobox.Items.Add(layer.Name);
            }

        }

 

View solution in original post

0 Kudos
1 Reply
SteveCole
Frequent Contributor

In answer to my own question, my Googling finally brought forth a solution that worked for referencing the control. Here's how I have implemented it:

        private void cboLayerList_Loaded(object sender, RoutedEventArgs e)
        {
            var layerlist = MapView.Active.Map.GetLayersAsFlattenedList().OfType<BasicRasterLayer>();
            var theCombobox = (System.Windows.Controls.ComboBox)this.FindName("cboLayerList");

            theCombobox.Items.Clear();

            foreach (var layer in layerlist) {
                theCombobox.Items.Add(layer.Name);
            }

        }

 

0 Kudos