Note that there are some explanatory texts on larger screens.

plurals
  1. POPutting Enum Description in an IEnumerable and ComboBox
    primarykey
    data
    text
    <p>I am still getting used to MVVM so if there is a better way to do this let me know. I do have to stick to a certain way of doing things so everything at the company I work at stays somewhat standard.I am trying to populate a combobox with the descriptions from my Enum class. I think this is an easy task, but I am not sure how to go about it. Any help is appreciated. If you need more code or information, please let me know. Code is below.</p> <p>I have my Descriptions in a class called Enum.cs:</p> <pre><code>[TypeConverter(typeof(EnumToStringUsingDescription))] public enum ArTypes { [Description("(All)")] arAll = 0, [Description("Adjustment")] [EnumInformation("Adjustment", true, 1)] arAdjustment = 1, [Description("Payment")] [EnumInformation("Payment", true, 2)] arPayment = 3, [Description("Deposit Receipt")] [EnumInformation("Deposit Receipt", true, 3)] arDepositReceipt = 5, [Description("Deposit Applied")] [EnumInformation("Deposit Applied", true, 4)] arDepositApplied = 7, [Description("Bad Debt Transfer")] [EnumInformation("Bad Debt Transfer", true, 5)] arBadDebtTransfer = 9, [Description("Bad Debt Writeoff")] [EnumInformation("Bad Debt Writeoff", true, 6)] arBadDebtWriteoff = 11, [Description("Bad Debt Recovery")] [EnumInformation("Bad Debt Recovery", true, 7)] arBadDebtRecovery = 13, [Description("Charge")] [EnumInformation("Charge", true, 8)] arCharge = 15, [Description("Immediate Case Receipt")] [EnumInformation("Immediate Cash Receipt", true, 9)] arImmediateCashReceipt = 17, [Description("Over Payment")] [EnumInformation("Over Payment", true, 10)] arOverPayment = 19, [Description("Balance Forward")] [EnumInformation("Balance Forward", true, 11)] arBalanceForward = 21 } </code></pre> <p>In my viewmodel I have the code to fill my combobox:</p> <pre><code>public IEnumerable&lt;ArTypes&gt; GetAllArTypesData() { try { //I believe the logic for setting the Ienumberable would go here } catch (Exception ex) { LogException(ex); } return null; } </code></pre> <p>To populate the combobox I am running this:</p> <pre><code>void PopulateComboLists() { CycleList = new ObservableCollection&lt;Cycle&gt;(); ServiceTypeList = new ObservableCollection&lt;ServiceType&gt;(); RateList = new ObservableCollection&lt;Rate&gt;(); CustomerTypeList = new ObservableCollection&lt;CustomerType&gt;(); ArCodeList = new ObservableCollection&lt;Arcode&gt;(); ArTypeList = new ObservableCollection&lt;ArTypes&gt;(); CycleList.Add(new Cycle() { CycleID = -1, CycleDescription = "(All)" }); ServiceTypeList.Add(new ServiceType() { ServiceTypeID = -1, ServiceDescription = "(All)" }); CustomerTypeList.Add(new CustomerType() { CustomerTypeID = -1, Description = "(All)" }); ArCodeList.Add(new Arcode() { ArcodeID = -1, Description = "(All)" }); foreach (var item in cycles) { CycleList.Add(item); } foreach (var item in serviceTypes) { ServiceTypeList.Add(item); } foreach (var item in rates) { RateList.Add(item); } foreach (var item in custTypes) { CustomerTypeList.Add(item); } foreach (var item in arCodes) { ArCodeList.Add(item); } foreach (var item in arTypes) { ArTypeList.Add(item); } } </code></pre> <p>Here is where the data is loaded onto the UI:</p> <pre><code>protected override void LoadDataStart() { //*Insert IsBusy and any other logic needed before database calls*// this.IsBusy = true; this.BusyMessage = "Generating Widget..."; try { //*Create a method for each database call - start a new task for each*// var taskCTR = Task.Factory.StartNew(() =&gt; GetAllCustomerTypeReportsData()).ContinueWith(results =&gt; GetAllCustomerTypeReportsDataContinue(results.Result)); var taskST = Task.Factory.StartNew(() =&gt; GetAllServiceTypesData()).ContinueWith(results =&gt; GetAllServiceTypesDataContinue(results.Result)); var taskRL = Task.Factory.StartNew(() =&gt; GetAllRatesData()).ContinueWith(results =&gt; GetAllRatesDataContinue(results.Result)); var taskCL = Task.Factory.StartNew(() =&gt; GetAllCyclesData()).ContinueWith(results =&gt; GetAllCyclesDataContinue(results.Result)); var taskCT = Task.Factory.StartNew(() =&gt; GetAllCustomerTypesData()).ContinueWith(results =&gt; GetAllCustomerTypesDataContinue(results.Result)); var taskAC = Task.Factory.StartNew(() =&gt; GetAllArCodesData()).ContinueWith(results =&gt; GetAllArCodesDataContinue(results.Result)); var taskAT = Task.Factory.StartNew(() =&gt; GetAllArTypesData()).ContinueWith(results =&gt; GetAllArTypesDataContinue(results.Result)); Task[] allTasks = new Task[7] { taskCTR, taskST, taskRL, taskCL, taskCT, taskAC, taskAT }; Task.Factory.ContinueWhenAll(allTasks, loadDataContinue =&gt; { Action executeContinue = () =&gt; { PopulateComboLists(); if (CanLoad) { LoadDataContinue(); IsBusy = false; } else ShowOptionsView(); }; this.UIDispatcher.Invoke(executeContinue); }); } catch (Exception ex) { LogException(ex); } //*Base class will call LoadDataContinue() once the database calls are complete*// } </code></pre> <p>XAML:</p> <pre><code>&lt;Label VerticalAlignment="Center" Margin="5,0,0,0" Content="ArType: " Grid.Row="5" Grid.Column="0"&gt;&lt;/Label&gt; &lt;telerik:RadComboBox ItemsSource="{Binding ArTypeList}" DisplayMemberPath="Key" SelectedValuePath="Value" HorizontalAlignment="Left" Width="190" SelectedValue="{Binding Path=SelectedArType, Mode=TwoWay, ValidatesOnDataErrors=True}" TabIndex="5" Grid.Row="5" VerticalAlignment="Center" Grid.Column="1" Style="{StaticResource RadComboBoxStyle}" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload