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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:40:48+00:00 2026-05-17T20:40:48+00:00

I’ve a very trivial requirement which makes me go nuts. I’ve a DataGridView in

  • 0

I’ve a very trivial requirement which makes me go nuts. I’ve a DataGridView in windows forms application. This contains one databound ComboBox Column. I’m using DisplayMember and ValueMember properties of that combobox.

Now my requirement is ComboBox should show the list of DisplayMembers in drop down list but when user selects one item from it, I should display the part of that DisplayMember in the combobox cell visible to the user. For example.

My display member list looks as below:

“Cust1 – Customer 1”
“Cust2 – Customer 2”
“Cust3 – Customer 3”

and when user selects any one of them from the above list (Say user selected ‘Cust2 – Customer 2’) then I need to display the value in the combobox column cell as only “Cust2” instead of complete DisplayMember text.

This DisplayMember list is a combination of two fields from the datasource bound to it i.e. First part points to CustomerCode field and second part points Customer name. I need to display only CustomerCode in the ComboBox cell after user selects one item from the drop down list.

How can I do this? Or should I come up with my own control which will have a different AutoCompleteCustomSource and display member value. Even I’m confused with that approach too.

Update: As no one has come up with any solution to my problem. Now I’m starting a bounty for that, also if anyone can suggest me other way to implement the same functionality, it would be great.

I’ve even tried to come up with my own control and tried to work on simple combobox to display a different value than the selected dropdown list, even that didn’t work. Is there any other way to implement this? Any tips and tricks are greatly appreciable.

@Anurag: Here is the code which I’ve used.
Created a datagridview in the design mode. Created one column of type ‘DataGridViewComboBoxColumn’ that and named it as CustomerColumn.

In the designer file it looks like below:

private System.Windows.Forms.DataGridViewComboBoxColumn CustomerColumn;

This is the entity class which I’ve used for datasource

 public class Customer
 {
    public int Id { get; set; }
    public string CustCode { get; set; }
    public string CustName { get; set; }
    public string NameWithCode { get; set; }// CustCode - CustName format
 }

In the form load event I’m doing the following:

  CustomerColumn.DataSource = GetCustomers();
  CustomerColumn.DisplayMember = "NameWithCode";
  CustomerColumn.ValueMember = "Id";
  • 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-17T20:40:49+00:00Added an answer on May 17, 2026 at 8:40 pm

    I’m answering my own question because I’ve implemented my own solution to this by using custom control.

    This custom control is created by keeping a textbox above combo box in such a way that only drop down button of combobox is visible.

    Now I’ve created a custom column in datagridview deriving the DataGridViewEditingControl from my usercontrol.

    I’ve added a property in Usercontrol which will take drop down list source from the control which is hosting datagridview.

    Now in the EditingControlShowing event I’m setting this property as below

    private void dataGridView2_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
      if(dataGridView2.CurrentCell.ColumnIndex.Equals(0) && e.Control is UserControl1)
      {
        var uscontrol = e.Control as UserControl1;
        uscontrol.DropDownListSource = source;
      }
    }
    

    This drop down list source is used in the usercontrol to set the autocompletesource to the textbox and datasource to the combobox as below:
    Whenever I set the DropDownDataSource I’m firing an event in the usercontrol which will do the following. This is to ensure that every time EditingControlShowing event occurs for this column in DataGridView, this source is updated for textbox and combobox in usercontrol.

    private void DropDownSourceChanged(object sender, EventArgs eventArgs)
    {
      textBox1.AutoCompleteCustomSource = DropDownListSource;
      textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
      textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
    
      comboBox1.DataSource = DropDownListSource;
    }
    

    Now whenever user starts typing in the textbox autocomplete source will display dropdown list with ‘NameWithCode’ values and if user selects one of them then I’ll set it to the Text propery overidden in my usercontrol which will be used for the cell value in the DataGridView. Now based on the Textbox text (which is NameWithCode) I can get the code part and set it to the text property.
    If user uses combobox dropdown button to select the item then I’ll get the combobox selected text and set it in the Textbox which is ultimately used by the cell for getting value.

    This way I could achieve the solution I want.

    @Homam, solution also works but when I change the ComboBox’s DropDownStyle to allow the user to type the value in the combobox it behaves weirdly and not getting up to the mark solution for my requirement. Hence I used this solution.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.