Why is the selectedtext in the combobox aligned the to the right where every other item is aligned to the left.

Posted on 2006-03-21
Last Modified: 2010-04-16
Following is a code snippet

cboSystemStatus.DataSource = objRPlayer.GetSystemStatusDescriptions();   // <- Datatable prepopulated from stored procedure
cboSystemStatus.ValueMember = "systemStatusID".ToString().Trim();
cboSystemStatus.DisplayMember = "SystemStatusDescription".ToString().Trim();
//cboSystemStatus.SelectedValue = objRPlayer.SystemStatusID;

Now every thing appears perfectly when i drop down my combobox.   All Display members appear perfectly.   No problem there....

When i select an item in the combobox.  The selected displaymember appears to be cut off by the first few characters.  As if the trim function is not being preformed correctly and being aligned from the right hand side.

I'm a bit of a newbie with windows forms.  Can somebody tell my why only the selected text is out of place?????

Thanks in Advance

Question by:camdempster
    LVL 8

    Accepted Solution

    Hi camdempster,

    cboSystemStatus.DisplayMember = "SystemStatusDescription".ToString().Trim();
    this line isn't trim because "SystemStatusDescription".ToString().Trim() = "SystemStatusDescription".

    Don't trim your field name :) Please trim values of records in your table.

    see this sample:

    tableset ts = objRPlayer.GetSystemStatusDescriptions();

    for (int i=0;i<ts.rows.count;i++)
         ts.rows[i]["SystemStatusDescription"] = ts.rows[i]["SystemStatusDescription"].tostring().trim();

    Good luck,

    Author Comment

    Bang on VINHNL,

    Thanks dude, worked perfectly.  Is there not an easier way of doing it though?  I just thought I could trim the column rather than traverse through and trim each cell?

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    733 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

    21 Experts available now in Live!

    Get 1:1 Help Now