combo box dispaly memeber ,value in c# windows form

Posted on 2007-08-12
Last Modified: 2013-12-17
i had a combo box  the field length of it is 1 char in database but the user should be able to see "default " and "override" text in combobox . how to store it in the collection so that it should be 1 char in storage but the displaymember should be "overide" or "default" this is "windowsform" app
plse help me
Question by:kranthi4uonly
    LVL 96

    Expert Comment

    by:Bob Learned
    Are setting the DisplayMember and the ValueMember?

    LVL 5

    Expert Comment

    I think your problem is starts with your database design. Changing your database field to bit(bool) and use radio button or changing your database field to varchar(x)  and use combobox could solve your problem. Or you could use a view dataset (select ...CASE myfield=d then "default" else "override") get(show) your data with combobox and table dataset to update your data(you should collect the data by yourself from your form's controls).

    Author Comment

    so can u pleasse help me how to d oia ma fresher so canu help me thanks
    LVL 5

    Expert Comment

    Sure kranthi4uonly,
    If I were you I would change the database strucure because there is no meaning to use char(1) in your database.
    If you use this field many times in your applications and database structure and want your database size smaller and your database faster(if you have a large database) you can change it to bit(1 or 0) could be solution.
    Or if your database is not large and there is no need to performance and you need this field as string in your code, change it to varchar(8) and it will became more easy to manage this field.

    You must decide which one do you prefer?

    Then if your database have data, I will help you change the database's meta data.
    if not it is a piece of cake :)
    I'm waiting for your decision.


    Author Comment

    hi kosturdur
    i cant change database it is not in my hands and hte databse holds some thousand s at tiems milions of records so it is not posible ot do change it

    and one more thing is iam using  menu -->data--->datasources and if u do show datasources u wil get all the colum names of the datatable on left side  so i selected combobox for that colum and draged it on form so automaticaly it will bind to the colum and the xml fiel will be created so before binding itself i have to do some thing so how to do it frm here please help me
    LVL 5

    Accepted Solution

    hi kranthi4uonly,
    In Solution Explorer right-click to your project and select "add" then select "new item" then choose a dataset. From Menu-->View-->Server Explorer get connected to your database, find your table then drag&drop your table into the dataset. Then right click to the table on the dataset and choose configure. While configuring your sql string instead of default sql write;
     SELECT    A, B, MyField, (CASE WHEN MyField = 'd' THEN 'default' ELSE 'override' END) AS MyFieldExplanation
    FROM         MyTable
    then menu -->data--->datasources-->show datasources before dropping your fields change the MyFieldExplanation to combobox by selecting from the dropdown near the field. Now you can see the 'default' and 'override' but I don't know how you manage the update, insert, delete events. You could do this by code from another dataset and then refresh this one. You could open another topic for that.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Title # Comments Views Activity
    Use a Dot Net dll in VBA 56 58
    Contant UI messages in .NET 1 17
    Refactor .net copy files method 8 38
    Richtextbox formatting 8 18
    Normally a window is moved by clicking on the caption bar and dragging. You may want your user to be able to move borderless forms or move a form by clicking anywhere in the form without the limitation to the caption bar. There are many ways to do i…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now