Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6696627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:21:50+00:00 2026-05-26T06:21:50+00:00

This may sound trivial but i have a problem with setting selected item in

  • 0

This may sound trivial but i have a problem with setting selected item in ComboBox 😉

What i want to achive:

I want to have the first element of the list selected after the page loads.

XAML Code:

               <DataTemplate>
                                    <ComboBox x:Name="DeviceComboBox" SelectedIndex="1" SelectionChanged="DeviceComboBox_SelectionChanged">
                                        <ComboBox.Items>
                                            <ComboBoxItem x:Name="Switch" Content="Switche"/>
                                            <ComboBoxItem x:Name="Firewall" Content="Firewalle"/>
                                            <ComboBoxItem x:Name="Host" Content="Hosty" />
                                            <ComboBoxItem x:Name="SRF1" Content="SRF1"/>
                                        </ComboBox.Items>
                                    </ComboBox>
                                </DataTemplate>

RESULT:
AG_E_UKNOWN_ERROR [Line:49 Position:55]
Line 49:

</ComboBox>

Error Details

    w MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
    w MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)
    w MS.Internal.XcpImports.DataTemplate_LoadContent(DataTemplate template)
    w System.Windows.Controls.DataGridTemplateColumn.GenerateElement(DataGridCell cell, Object dataItem)
    w System.Windows.Controls.DataGrid.PopulateCellContent(Boolean isCellEdited, DataGridColumn dataGridColumn, DataGridRow dataGridRow, DataGridCell dataGridCell)
    w System.Windows.Controls.DataGrid.AddNewCellPrivate(DataGridRow row, DataGridColumn column)
    w System.Windows.Controls.DataGrid.CompleteCellsCollection(DataGridRow dataGridRow)
    w System.Windows.Controls.DataGrid.GenerateRow(Int32 rowIndex, Int32 slot, Object dataContext)
    w System.Windows.Controls.DataGrid.InsertElementAt(Int32 slot, Int32 rowIndex, Object item, DataGridRowGroupInfo groupInfo, Boolean isCollapsed)
    w System.Windows.Controls.DataGrid.InsertRowAt(Int32 rowIndex)
    w System.Windows.Controls.DataGridDataConnection.NotifyingDataSource_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
    w System.Windows.Data.PagedCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
    w System.Windows.Data.PagedCollectionView.ProcessAddEvent(Object addedItem, Int32 addIndex)
    w System.Windows.Data.PagedCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args) 
    w System.Windows.Data.PagedCollectionView.<.ctor>b__0(Object sender, NotifyCollectionChangedEventArgs args)
    w System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
    w System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
    w System.Collections.ObjectModel.Collection`1.Add(T item)
    w LANOS.Views.Customers.onCustomerListLoaded(LoadOperation`1 loadOper)
    w System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass13`1.<Load>b__11(LoadOperation lo)
    w System.ServiceModel.DomainServices.Client.LoadOperation.<>c__DisplayClass4`1.<Create>b__0(LoadOperation`1 arg)
    w System.ServiceModel.DomainServices.Client.LoadOperation`1.InvokeCompleteAction()
    w System.ServiceModel.DomainServices.Client.OperationBase.Complete(Object result)
    w System.ServiceModel.DomainServices.Client.LoadOperation.Complete(DomainClientResult result)
    w System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
    w System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )

Caused by: AG_E_UNKNOWN_ERROR [Line: 49 Position: 55]

    w MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
    w MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)
    w MS.Internal.XcpImports.DataTemplate_LoadContent(DataTemplate template)
    w System.Windows.Controls.DataGridTemplateColumn.GenerateElement(DataGridCell cell, Object dataItem)
    w System.Windows.Controls.DataGrid.PopulateCellContent(Boolean isCellEdited, DataGridColumn dataGridColumn, DataGridRow dataGridRow, DataGridCell dataGridCell)
    w System.Windows.Controls.DataGrid.AddNewCellPrivate(DataGridRow row, DataGridColumn column)
    w System.Windows.Controls.DataGrid.CompleteCellsCollection(DataGridRow dataGridRow)
    w System.Windows.Controls.DataGrid.GenerateRow(Int32 rowIndex, Int32 slot, Object dataContext)
    w System.Windows.Controls.DataGrid.InsertElementAt(Int32 slot, Int32 rowIndex, Object item, DataGridRowGroupInfo groupInfo, Boolean isCollapsed)
    w System.Windows.Controls.DataGrid.InsertRowAt(Int32 rowIndex)
    w System.Windows.Controls.DataGridDataConnection.NotifyingDataSource_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
    w System.Windows.Data.PagedCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
    w System.Windows.Data.PagedCollectionView.ProcessAddEvent(Object addedItem, Int32 addIndex)
    w System.Windows.Data.PagedCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
    w System.Windows.Data.PagedCollectionView.<.ctor>b__0(Object sender, NotifyCollectionChangedEventArgs args)
    w System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
    w System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
    w System.Collections.ObjectModel.Collection`1.Add(T item)
    w LANOS.Views.Customers.onCustomerListLoaded(LoadOperation`1 loadOper)
    w System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass13`1.<Load>b__11(LoadOperation lo)
    w System.ServiceModel.DomainServices.Client.LoadOperation.<>c__DisplayClass4`1.<Create>b__0(LoadOperation`1 arg)
    w System.ServiceModel.DomainServices.Client.LoadOperation`1.InvokeCompleteAction()
    w System.ServiceModel.DomainServices.Client.OperationBase.Complete(Object result)
    w System.ServiceModel.DomainServices.Client.LoadOperation.Complete(DomainClientResult result)
    w System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
    w System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:21:50+00:00Added an answer on May 26, 2026 at 6:21 am

    As I read in your comments you want to use a ComboBox which automatically has a selection when it is loaded. Therefore I would suggest two possibilities: Writing a control deriving from ComboBox or adding a behavior to a default ComboBox.

    Deriving from ComboBox:

    public class MyComboBox : ComboBox
    {
      public MyComboBox()
      {
        Loaded += ComboBoxLoaded;
      }
    
      private void ComboBoxLoaded(object sender, RoutedEventArgs e)
      {
        if(Count > 1)
        {
          SelectedIndex = 1;
        }
      }
    }
    

    Usage:

    <MyComboBox>
      <ComboBoxItem x:Name="Switch" Content="Switche"/>
      <ComboBoxItem x:Name="Firewall" Content="Firewalle"/>
      <ComboBoxItem x:Name="Host" Content="Hosty" />
      <ComboBoxItem x:Name="SRF1" Content="SRF1"/>
    </MyComboBox>
    

    Implementing behavior:

    A behavior class allows you to add a behavior to a control using xaml. The behavior is coded.

    public class ComboBoxSelectionBehavior:Behavior<ComboBox>
    {
      protected override void OnAttached()
      {
        base.OnAttached();
        AssociatedObject.Loaded += ComboBoxLoaded;
      }
    
      protected override void OnDetaching()
      {
        AssociatedObject.Loaded -= ComboBoxLoaded;
        base.OnDetaching();
      }
    
      private void ComboBoxLoaded(object sender, RoutedEventArgs e)
      {
        if(Count > 1)
        {
          SelectedIndex = 1;
        }
      }
    }
    

    Usage:

    <ComboBox>
      <Interactivity:Interaction.Behaviors>
        <Behaviors:ComboBoxSelectionBehavior/>
      </Interactivity:Interaction.Behaviors>
      <ComboBoxItem x:Name="Switch" Content="Switche"/>
      <ComboBoxItem x:Name="Firewall" Content="Firewalle"/>
      <ComboBoxItem x:Name="Host" Content="Hosty" />
      <ComboBoxItem x:Name="SRF1" Content="SRF1"/>
    </ComboBox>
    

    Note, that for the usage of behaviors you need the Blend SDK to be installed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this may sound kind of convoluted but basically i want to have a form
This may sound stupid but... When I create big SQL commands I want to
This may sound very noobish but I have tried to read the forum posts
This may sound awkward ... But I didn't understand it. Why do we have
This may sound silly but I didn't want to hijack a question. I recently
This may sound too trivial for an intermediate Java programmer. But during my process
This may sound trivial, but what is the difference between Dim v As String()
This may sound easy, but please, I am a newbie. I have a simple
This may sound really stupid. but I've got a strange problem with the D
This may sound like a simple and trivial question, but I'm using the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.