0

This is a little difficult to describe, so bear with me. C#, WPF This combobox in a stackpanel:

<ComboBox x:Name="ddlProviderStatuses" 
                      ItemsSource="{Binding vwProviderStatus}"
                      DisplayMemberPath="StatusName"
                      SelectedValuePath="ID"
                      Height="21"
                      Width="100"
                      Margin="0,0,0,0" 
                      IsReadOnly="True"
                      SelectionChanged="ddlProviderStatus_SelectionChanged"
                       />

This code to bind:

private void ddlProvidersStatusBind()
        {
            cnWkbProviderStatuses ProviderStatuses = new cnWkbProviderStatuses();
            var Statuses = ProviderStatuses.vwProviderStatuses.ToList();
            ProvStatus = Statuses;
            DataContext = ProvStatus;
        }

Works great. Returns the 4 statuses desired.

Separately I have a listview:

<ListView x:Name="lvProviders" 
                      ItemsSource="{Binding}"
                      DisplayMemberPath="Tenant"
                      SelectedValuePath="TenantTID"
                      Height="Auto"
                      Width="Auto"
                      Margin="0,10,0,0"/>

This code to bind:

private void ProviderListBind()
        {
            cnWkbProviderList vwProviders = new cnWkbProviderList();
            var ProvList = vwProviders.vwProviderTenants.ToList();
            ProviderList = ProvList;
            DataContext = ProviderList;
        }

Works great. Now the listview is not bound until after a selection is made in the combobox because I'm working towards having the Provider List filtered based on selection:

private void ddlProviderStatus_SelectionChanged(object sender, RoutedEventArgs e)
        {
            ProviderListBind();

            //lvProviders.Items.Filter = FilterProviders; Haven't successfully applied the filter yet, so disregard for the moment.

            ListCount = lvProviders.Items.Count;
            switch (ListCount)
            {
                case 0:
                    strStatus = "No records found.";
                    break;
                case 1:
                    strStatus = "One record found.";
                    break;
                default:
                    strStatus = ListCount + " records found.";
                    break;
            }
            labStatus.Content = strStatus;
        }

This code works fine, the listview is populated and the row count is displayed. But, after making the combobox selection, the combobox no longer has 4 values in it, but rather hundreds of blank values (and the original 4 are gone).

I thought it might have been because I was trying to use the same connection string for both, so I rebuilt everything keeping each ADO Entity Model separate in separate models. But I keep getting the same result. Not only do I not understand the blank row in the combobox, but I don't understand why the combobox is executing the binding action again.

Thanks in advance.

  • Is it the "DataContext = ProviderList;" that's updating the "DataContext = ProvStatus;"? – Guarandingo Jun 02 '23 at 01:25
  • Added a datagrid to the stackpanel. Upon loading datagrid data, now both the combobox and the listview have the number of records as the datagrid. Of course they don't show any values since the fields are not mapped to those objects. So with each load of a dataset, the other objects are having their datacontexts changed. Must be something pretty basic that I'm missing. – Guarandingo Jun 04 '23 at 16:43

0 Answers0