<?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: How to retrieve all items in listbox and put them to a string? in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-retrieve-all-items-in-listbox-and-put-them/m-p/854624#M4439</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Helen,&lt;/P&gt;&lt;P&gt;The answer depends on your ExcelData property. If your ExcelData property is type of List&amp;lt;string&amp;gt;, then&amp;nbsp;&lt;/P&gt;&lt;P&gt;string strAllAccount =&amp;nbsp;string.Join("', '", &lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;ExcelData&lt;/SPAN&gt;.ToArray());&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 May 2020 05:19:11 GMT</pubDate>
    <dc:creator>GKmieliauskas</dc:creator>
    <dc:date>2020-05-20T05:19:11Z</dc:date>
    <item>
      <title>How to retrieve all items in listbox and put them to a string?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-retrieve-all-items-in-listbox-and-put-them/m-p/854623#M4438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;ListBox x:Name="lstAllAcct" Grid.Row="1"&amp;nbsp; ItemsSource="{Binding ExcelData}"/&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;Button x:Name="btnNewSelection" Command="{Binding Path=NewSelectionCmd}"&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;{Binding ExcelData}&lt;/STRONG&gt; is to get accounts from excel sheet to my listbox : done&lt;/P&gt;&lt;P&gt;Now when button btnNewSelection is click I want to get all accounts in that listbox to a string (to construct my query statement)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;The code behind for the button:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;private RelayCommand _newSelectionCmd;&lt;BR /&gt;public ICommand NewSelectionCmd&lt;BR /&gt;{&lt;BR /&gt;get&lt;BR /&gt;{&lt;BR /&gt;if (_newSelectionCmd == null)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;_newSelectionCmd = new RelayCommand(() =&amp;gt; DoSearch(), () =&amp;gt; true);&lt;/P&gt;&lt;P&gt;return _newSelectionCmd;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;private void DoSearch ()&lt;BR /&gt; {&lt;/P&gt;&lt;P&gt;string strAllAccount =""&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(how to I get all items in my listbox to strAllAccount?)&lt;/STRONG&gt;&lt;BR /&gt; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Your&amp;nbsp;help is&amp;nbsp;very much appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2020 19:15:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-retrieve-all-items-in-listbox-and-put-them/m-p/854623#M4438</guid>
      <dc:creator>helenchu</dc:creator>
      <dc:date>2020-05-19T19:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve all items in listbox and put them to a string?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-retrieve-all-items-in-listbox-and-put-them/m-p/854624#M4439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Helen,&lt;/P&gt;&lt;P&gt;The answer depends on your ExcelData property. If your ExcelData property is type of List&amp;lt;string&amp;gt;, then&amp;nbsp;&lt;/P&gt;&lt;P&gt;string strAllAccount =&amp;nbsp;string.Join("', '", &lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;ExcelData&lt;/SPAN&gt;.ToArray());&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2020 05:19:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-retrieve-all-items-in-listbox-and-put-them/m-p/854624#M4439</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2020-05-20T05:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve all items in listbox and put them to a string?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-retrieve-all-items-in-listbox-and-put-them/m-p/854625#M4440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, in my case, after loading ExcelData, I move the item(s) around to other listboxes depends on the type.&lt;/P&gt;&lt;P&gt;So let me rephrase my question,&amp;nbsp;&lt;/P&gt;&lt;P&gt;below is my listbox&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;lt;ListBox x:Name="lslSubjAcct" /&amp;gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Because I wrote codes to&amp;nbsp;load&amp;nbsp;data to&amp;nbsp;&lt;SPAN&gt;lstSubjAcct listbox&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;in a button click event therefore I have no&amp;nbsp;ItemsSource binding in my xaml file.&lt;/P&gt;&lt;P&gt;Now I need to get all items in my lstSubjAcct listbox to a string in the viewmodel, how do I do that ?&amp;nbsp; Thank you!&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;private void BtnAddSubject_Click(object sender, RoutedEventArgs e)&lt;BR /&gt; { &lt;BR /&gt; string currentItemText;&lt;BR /&gt; int currentItemIndex;&lt;BR /&gt; List&amp;lt;string&amp;gt; myDataList = new List&amp;lt;string&amp;gt;();&lt;/P&gt;&lt;P&gt;foreach (object item in lstAllAcct.Items)&lt;BR /&gt; myDataList.Add(item as string);&lt;/P&gt;&lt;P&gt;// Find the right item and it's value and index &lt;BR /&gt; currentItemText = lstAllAcct.SelectedValue.ToString();&lt;BR /&gt; currentItemIndex = lstAllAcct.SelectedIndex;&lt;BR /&gt; lslSubjAcct.Items.Add(currentItemText);&lt;BR /&gt; if (myDataList != null)&lt;BR /&gt; {&lt;BR /&gt; myDataList.RemoveAt(currentItemIndex);&lt;BR /&gt; }&lt;BR /&gt; // Refresh data binding &lt;BR /&gt; ApplyDataBinding(myDataList);&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt; private void ApplyDataBinding(List&amp;lt;string&amp;gt; myNewDataList)&lt;BR /&gt; {&lt;BR /&gt; lstAllAcct.ItemsSource = null;&lt;BR /&gt; // Bind ArrayList with the ListBox &lt;BR /&gt; lstAllAcct.ItemsSource = myNewDataList;&lt;BR /&gt; &lt;BR /&gt; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2020 14:55:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-retrieve-all-items-in-listbox-and-put-them/m-p/854625#M4440</guid>
      <dc:creator>helenchu</dc:creator>
      <dc:date>2020-05-20T14:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve all items in listbox and put them to a string?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-retrieve-all-items-in-listbox-and-put-them/m-p/854626#M4441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Helen,&lt;/P&gt;&lt;P&gt;&amp;nbsp;It appears that you are not using MVVM which is&amp;nbsp;the programming pattern used by Dockpanes in the Pro SDK.&amp;nbsp; MVVM is programming pattern not specific to the Pro SDK and is used in many Enterprise implementations for WPF desktop applications.&amp;nbsp; If you look at this question:&amp;nbsp;&lt;A _jive_internal="true" class="link-titled" href="https://community.esri.com/message/922908-re-access-listview-inside-dockpane?commentID=922908#comment-922908" title="https://community.esri.com/message/922908-re-access-listview-inside-dockpane?commentID=922908#comment-922908"&gt;https://community.esri.com/message/922908-re-access-listview-inside-dockpane?commentID=922908#comment-922908&lt;/A&gt;&amp;nbsp;&amp;nbsp;it explains the issue that you are running into.&amp;nbsp; In order to implement a button (or command) for example you have to use the ICommand pattern by implementing a public property that implements the ICommand Interface in the ViewModel.&amp;nbsp; Remember all your code goes into the ViewModel not in the View's (xaml.cs) code behind file.&amp;nbsp; So don't double click a button control to implement an 'OnClick' handler, there are no handlers in MVVM.&amp;nbsp; &amp;nbsp;I attached a 2.5 sample that implements a listbox, a textbox, and a set of buttons in MVVM.&amp;nbsp; Remember the the View (your XAML) and the ViewModel (your code in the viewmodel.cs file) are linked by using Data Binding.&amp;nbsp; So the public properties in your ViewModel code have to have a corresponding property with {Binding property_name}.&amp;nbsp; In the ViewModel code you would use either&amp;nbsp;SetProperty or NotifyPropertyChanged in order to make a change (with is normally in the setter of the property) to either your list or any other property (see for example the ListItem class in my sample). Using &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;SetProperty or&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;NotifyPropertyChanged will ensure that the UI (your XAML) is notified that your data (properties) has changed and&amp;nbsp;the UI can now update the control on the display.&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2020 18:13:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-retrieve-all-items-in-listbox-and-put-them/m-p/854626#M4441</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2020-05-20T18:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve all items in listbox and put them to a string?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-retrieve-all-items-in-listbox-and-put-them/m-p/854627#M4442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much Wolfgang for the sample codes and specially spending time to explain&amp;nbsp;them in details.&amp;nbsp; I'm studying them right now.&amp;nbsp; Hopefully 1 day I will be more comfortable with coding in&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;MVVM.&amp;nbsp; Your help is very much appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 May 2020 17:01:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-retrieve-all-items-in-listbox-and-put-them/m-p/854627#M4442</guid>
      <dc:creator>LeLuong</dc:creator>
      <dc:date>2020-05-21T17:01:58Z</dc:date>
    </item>
  </channel>
</rss>

