<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Adding items to combobox list using a dictionary in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1606097#M12831</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/456188"&gt;@mstranovsky&lt;/a&gt;&amp;nbsp; Your code snippet is not applicable in an ArcGIS Pro Add-in.&amp;nbsp; There are two patterns in ArcGIS Pro to deploy a ComboBox:&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; &amp;nbsp;If you are using a Pro Combo box ribbon control you would load the 'Ribbon' Dropdown from a dictionary like this:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class TestComboBox : ComboBox
{
	private bool _isInitialized;

	/// &amp;lt;summary&amp;gt;
	/// Combo Box constructor
	/// &amp;lt;/summary&amp;gt;
	public TestComboBox()
	{
		UpdateCombo();
	}

	// create a dictionary with an entry for each US state, the value should be the capital city of that state
	private Dictionary&amp;lt;string, string&amp;gt; _stateCapitals = new Dictionary&amp;lt;string, string&amp;gt;
	{
		{ "Alabama", "Montgomery" },
		{ "Alaska", "Juneau" },
		{ "Arizona", "Phoenix" },
		{ "Arkansas", "Little Rock" },
		{ "California", "Sacramento" },
		{ "Colorado", "Denver" },
		{ "Connecticut", "Hartford" },
		{ "Delaware", "Dover" },
		{ "Florida", "Tallahassee" },
		{ "Georgia", "Atlanta" }
	};

	/// &amp;lt;summary&amp;gt;
	/// Updates the combo box with all the capitals of the US states
	/// &amp;lt;/summary&amp;gt;
	private void UpdateCombo()
	{
		if (_isInitialized)
			SelectedItem = ItemCollection.FirstOrDefault();
		if (!_isInitialized)
		{
			// Updates the combo box with all the capital names of the US states
			foreach (var capital in _stateCapitals.Values)
			{
				Add(new ComboBoxItem(capital));
			}
			_isInitialized = true;
		}
		Enabled = true;
		SelectedItem = ItemCollection.FirstOrDefault();
	}

	/// &amp;lt;summary&amp;gt;
	/// The on comboBox selection change event. 
	/// &amp;lt;/summary&amp;gt;
	/// &amp;lt;param name="item"&amp;gt;The newly selected combo box item&amp;lt;/param&amp;gt;
	protected override void OnSelectionChange(ComboBoxItem item)
	{
		if (item == null) return;
		if (string.IsNullOrEmpty(item.Text)) return;
	}
}&lt;/LI-CODE&gt;&lt;P&gt;2. If you are using a combobox on a Dockpane, you should use the MVVM pattern to populate the combobox content.&amp;nbsp; In this case, please model your code after&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/760068"&gt;@SumitMishra_016&lt;/a&gt;&amp;nbsp;'s sample snippet.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Apr 2025 16:11:13 GMT</pubDate>
    <dc:creator>Wolf</dc:creator>
    <dc:date>2025-04-15T16:11:13Z</dc:date>
    <item>
      <title>Adding items to combobox list using a dictionary</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1602282#M12813</link>
      <description>&lt;P&gt;I have a dictionary of values named "odDict".&amp;nbsp; &amp;nbsp;When i use the following code it only adds the first value in the dictionary.&amp;nbsp; How can i get it to populate the list using all values in the dictionary?&lt;/P&gt;&lt;P&gt;foreach (KeyValuePair&amp;lt;string, string&amp;gt; kvp in odDict)&lt;BR /&gt;{&lt;BR /&gt;string key = kvp.Key;&lt;BR /&gt;string val = kvp.Value;&lt;BR /&gt;cmbOverlayDistrict.Items.Add(val);&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 12:16:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1602282#M12813</guid>
      <dc:creator>mstranovsky</dc:creator>
      <dc:date>2025-04-03T12:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Adding items to combobox list using a dictionary</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1602290#M12814</link>
      <description>&lt;P&gt;You can use:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;List&amp;lt;object&amp;gt; values = odDict.Values.ToList();
cmbOverlayDistrict.Items.AddRange(items: values.ToArray());&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 03 Apr 2025 12:31:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1602290#M12814</guid>
      <dc:creator>RadekMandovec</dc:creator>
      <dc:date>2025-04-03T12:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Adding items to combobox list using a dictionary</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1602319#M12815</link>
      <description>&lt;P&gt;Thank you for the reply but when using your code I now see this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mstranovsky_0-1743688270209.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/129380iFEF3D0A6FA21E787/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mstranovsky_0-1743688270209.png" alt="mstranovsky_0-1743688270209.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mstranovsky_1-1743688287829.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/129381i07EF155303F02B24/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mstranovsky_1-1743688287829.png" alt="mstranovsky_1-1743688287829.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mstranovsky_2-1743688310143.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/129382iC07CE04CD0AD4A95/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mstranovsky_2-1743688310143.png" alt="mstranovsky_2-1743688310143.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 13:52:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1602319#M12815</guid>
      <dc:creator>mstranovsky</dc:creator>
      <dc:date>2025-04-03T13:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: Adding items to combobox list using a dictionary</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1602632#M12817</link>
      <description>&lt;P&gt;And if you use this?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;List&amp;lt;object&amp;gt; values= new(odDict.Values);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 04:21:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1602632#M12817</guid>
      <dc:creator>RadekMandovec</dc:creator>
      <dc:date>2025-04-04T04:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding items to combobox list using a dictionary</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1604593#M12822</link>
      <description>&lt;P&gt;I have put my sample code, it is working for me&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;ComboBox Name="CaseNumberComboBox" Width="200" ItemsSource="{Binding CaseNumbers}" SelectionChanged="CaseNumberComboBox_SelectionChanged"/&amp;gt;&lt;/LI-CODE&gt;&lt;LI-CODE lang="csharp"&gt;public ObservableCollection&amp;lt;string&amp;gt; CaseNumbers { get; set; } = new();


// Temporary list to avoid multiple UI updates
List&amp;lt;string&amp;gt; caseNumbersList = new();

while (await reader.ReadAsync())
{
    string caseNo = reader.GetString(0);
    caseNumbersList.Add(caseNo);
}

// Update UI on the main thread
System.Windows.Application.Current.Dispatcher.Invoke(() =&amp;gt;
{
    CaseNumbers.Clear();
    foreach (var caseNo in caseNumbersList)
    {
        CaseNumbers.Add(caseNo);
    }
    // Select the latest case number
    CaseNumberComboBox.SelectedItem = CaseNumbers.FirstOrDefault();
});&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 10 Apr 2025 11:09:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1604593#M12822</guid>
      <dc:creator>SumitMishra_016</dc:creator>
      <dc:date>2025-04-10T11:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Adding items to combobox list using a dictionary</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1606097#M12831</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/456188"&gt;@mstranovsky&lt;/a&gt;&amp;nbsp; Your code snippet is not applicable in an ArcGIS Pro Add-in.&amp;nbsp; There are two patterns in ArcGIS Pro to deploy a ComboBox:&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; &amp;nbsp;If you are using a Pro Combo box ribbon control you would load the 'Ribbon' Dropdown from a dictionary like this:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class TestComboBox : ComboBox
{
	private bool _isInitialized;

	/// &amp;lt;summary&amp;gt;
	/// Combo Box constructor
	/// &amp;lt;/summary&amp;gt;
	public TestComboBox()
	{
		UpdateCombo();
	}

	// create a dictionary with an entry for each US state, the value should be the capital city of that state
	private Dictionary&amp;lt;string, string&amp;gt; _stateCapitals = new Dictionary&amp;lt;string, string&amp;gt;
	{
		{ "Alabama", "Montgomery" },
		{ "Alaska", "Juneau" },
		{ "Arizona", "Phoenix" },
		{ "Arkansas", "Little Rock" },
		{ "California", "Sacramento" },
		{ "Colorado", "Denver" },
		{ "Connecticut", "Hartford" },
		{ "Delaware", "Dover" },
		{ "Florida", "Tallahassee" },
		{ "Georgia", "Atlanta" }
	};

	/// &amp;lt;summary&amp;gt;
	/// Updates the combo box with all the capitals of the US states
	/// &amp;lt;/summary&amp;gt;
	private void UpdateCombo()
	{
		if (_isInitialized)
			SelectedItem = ItemCollection.FirstOrDefault();
		if (!_isInitialized)
		{
			// Updates the combo box with all the capital names of the US states
			foreach (var capital in _stateCapitals.Values)
			{
				Add(new ComboBoxItem(capital));
			}
			_isInitialized = true;
		}
		Enabled = true;
		SelectedItem = ItemCollection.FirstOrDefault();
	}

	/// &amp;lt;summary&amp;gt;
	/// The on comboBox selection change event. 
	/// &amp;lt;/summary&amp;gt;
	/// &amp;lt;param name="item"&amp;gt;The newly selected combo box item&amp;lt;/param&amp;gt;
	protected override void OnSelectionChange(ComboBoxItem item)
	{
		if (item == null) return;
		if (string.IsNullOrEmpty(item.Text)) return;
	}
}&lt;/LI-CODE&gt;&lt;P&gt;2. If you are using a combobox on a Dockpane, you should use the MVVM pattern to populate the combobox content.&amp;nbsp; In this case, please model your code after&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/760068"&gt;@SumitMishra_016&lt;/a&gt;&amp;nbsp;'s sample snippet.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2025 16:11:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1606097#M12831</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2025-04-15T16:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding items to combobox list using a dictionary</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1608609#M12851</link>
      <description>&lt;P&gt;I attached a small sample add-in project that has a Combo dropdown on the ArcGIS Pro ribbon and two dropdowns on a Dockpane.&amp;nbsp; I am using a dictionary (keys and values) to 'feed' the dropdown content.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot1.png" style="width: 570px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/130830iA57B477A2FE8FCFF/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot1.png" alt="Screenshot1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 17:20:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-items-to-combobox-list-using-a-dictionary/m-p/1608609#M12851</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2025-04-23T17:20:24Z</dc:date>
    </item>
  </channel>
</rss>

