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 7010197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:57:37+00:00 2026-05-27T21:57:37+00:00

I’m trying to rig up a ComboBox with a Datagrid dropdown in WPF. I

  • 0

I’m trying to rig up a ComboBox with a Datagrid dropdown in WPF. I need the the code to be done programmatically and contained in the codebehind.

Here’s what I’ve got so far:

                        Dim cb As New ComboBox
                        Dim dg As New DataGrid

                        dg.AutoGenerateColumns = False

                        dg.ItemsSource = clnObjects 

                        Dim col_name As New DataGridTextColumn
                        col_name.Header = "Name"
                        col_name.Binding = New Binding("Name")
                        col_name.CanUserSort = False
                        col_name.CanUserResize = False

                        dg.Columns.Add(col_name)

                        Dim col_startdate As New DataGridTextColumn
                        col_startdate.Header = "Start Date"
                        col_startdate.Binding = New Binding("StartDate")
                        col_startdate.CanUserSort = False
                        col_startdate.CanUserResize = False

                        dg.Columns.Add(col_startdate)

                        cb.Items.Add(dg)

This code produces a ComboBox that contains a DataGrid with two columns and seems to look fine. Although when you click on the ComboBox and select one of the rows in the DataGrid the selection in the ComboBox doesn’t work properly. (It just shows the colum headers.)
I want the value in the first column of the selected row to appear as the ComboBox selection.

If anyone can help me with this issue it would be greatly appretiated.

Thanks,

Mike

  • 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-27T21:57:37+00:00Added an answer on May 27, 2026 at 9:57 pm

    It sounds like your want your ComboBox to contain items from clnObjects, but to display the DropDown using a DataGrid, not the defaultStackPanel.

    Right now your ComboBox is full of DataGrid controls, not whatever object is in clnObjects. This means when you select an item, you’re selecting a DataGrid, not the DataGrid.SelectedItem

    You could try changing it so the ComboBox’s display text contains ComboBox.SelectedItem.SelectedItem where the first SelectedItem is the DataGrid, however I still feel this is a bad design since you need to create a new DataGrid object per ComboBoxItem

    Instead I would recommend overwritting the default ComboBox.Template to display the ComboBox items in a DataGrid instead of in the default StackPanel. The default ComboBox Template can be found here. Just copy it and replace the StackPanel with IsItemsHost="True" to a DataGrid

    <Popup x:Name="Popup" ...>
        <Grid x:Name="DropDown" ...>
          <Border x:Name="DropDownBorder" ... />
          <ScrollViewer ...>
            <!-- Replace this with a DataGrid -->
            <StackPanel IsItemsHost="True"
                        KeyboardNavigation.DirectionalNavigation="Contained" />
          </ScrollViewer>
        </Grid>
      </Popup>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
i got an object with contents of html markup in it, for example: string

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.