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

  • Home
  • SEARCH
  • 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 7565947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:17:14+00:00 2026-05-30T14:17:14+00:00

i have a combobox which is bound to a datatable column like this: ComboBox.DataContext

  • 0

i have a combobox which is bound to a datatable column like this:

ComboBox.DataContext = DataDataTable;                
ComboBox.DisplayMemberPath = DataDataTable.Columns["IDNr"].ToString();

The IDNr in the Column always starts with 4 letters followed with the ID Number (ex. BLXF1234) .
I need to display the items in Combobox without the Letters (i need 1234 to be displayed in the combobox).

So i wrote a converter :

class IDPrefixValueConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value != null)
        {
            string s = value.ToString();
            if (s.Contains("BL"))
            {
                return s.Substring(4);
            }
            else
            {
                return s;
            }
        }
        return "";
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotSupportedException();
    }       

No, how can i tell the combobox to use the converter to display the items ?
i tried this in the Xaml:

ItemsSource="{Binding}" 
DisplayMemberPath="{Binding Converter={StaticResource IDPrefixValueConverter}}"

But still not working …any ideas ?
Thanks

  • 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-30T14:17:15+00:00Added an answer on May 30, 2026 at 2:17 pm

    You can modify the ItemTemplate of the ComboBox and use your converter:

    <ComboBox ItemsSource="{Binding}">
      <ComboBox.ItemTemplate>
        <DataTemplate>
          <TextBlock Text="{Binding Converter={StaticResource IDPrefixValueConverter}}"/>
        </DataTemplate>
      </ComboBox.ItemTemplate>
    </ComboBox>
    

    Each item is bound to the items in the ItemsSource. By using the converter in the binding you are able to perform the conversion you want.

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

Sidebar

Related Questions

I have a datagridview with a bound combobox column which contains decimal value. There
Say I have a DataGridView in which I dynamically build up a ComboBox column
I have a DataGrid bound to a DataView which, among other columns has, an
I have the DataTable with following columns: id, Name, Description, ParentId and would like
I have a comboxbox defined like this (basically): <ComboBox x:Name=pageViewSize> <ComboBox.Items> <ComboBoxItem IsSelected=True>5</ComboBoxItem> <ComboBoxItem>10</ComboBoxItem>
I have a data grid that looks like this <tk:DataGrid ItemsSource={Binding Parents} AutoGenerateColumns=False> <tk:DataGrid.Columns>
I have a ComboBox which I cannot bind directly to (due to this bug
I have a datagrid, which is bound to a RIA data object. this datagrid
I have 2 comboboxes, each are bound to the the same DataTable like so:
I have a WPF ComboBox which has its IsEditable property bound to a view

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.