list box formatting - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

list box formatting

pinkiepinkie Posts: 34Member
i have a listbox in which text is to be displayed coloumn wise as shown below

1 ABCD 23 21 12
2 wwww 23 22 22

Right now i am storing each item of a row in a CString. And for displaying each row i use the following code

sDisplayStr.Format("%-10s%-10s%-10s%-10s%-10s%", sSlNo, sName, sText1, sText2, sText3);

where sSlNo = "1", sName = "ABCD", sText1 = "23", sText2 = "21", sText3 = "12"

I am not able to format the text properly. could anybody help me out please?
Also i want to know how do i change the font of the list box contents to courier new?

tnx
pinkie

Comments

  • dwccgcdwccgc Posts: 576Member
    [blue]You are formating the text properly, you just need to change the font. There are two ways to change the font in a list box.

    1) Change the font for your whole application to "Courier New" by using the dialog properties option in your resource editor.

    2) Use the [/blue][red]OnDrawItem[/red][blue] method. See the below link for help.
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_clistbox.3a3a.drawitem.asp

    Just above and below the DrawText routine add the folloing code.
    [/blue]
    [code]
    CFont Font;
    CFont *pOldFont = NULL;
    if (Font.CreatePointFont(120, _T("Courier New"), &dc))
    {
    pOldFont = dc.SelectObject(&Font);
    }
    dc.DrawText(....);
    if (pOldFont != NULL)
    {
    dc.SelectObject(pOldFont);
    }
    [/code]

    : i have a listbox in which text is to be displayed coloumn wise as shown below
    :
    : 1 ABCD 23 21 12
    : 2 wwww 23 22 22
    :
    : Right now i am storing each item of a row in a CString. And for displaying each row i use the following code
    :
    : sDisplayStr.Format("%-10s%-10s%-10s%-10s%-10s%", sSlNo, sName, sText1, sText2, sText3);
    :
    : where sSlNo = "1", sName = "ABCD", sText1 = "23", sText2 = "21", sText3 = "12"
    :
    : I am not able to format the text properly. could anybody help me out please?
    : Also i want to know how do i change the font of the list box contents to courier new?
    :
    : tnx
    : pinkie
    :

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [blue]The 'Courier' will force you to scroll back and forth horizontally to see the whole record. When formatting use ' ' to separate the strings from each other and in the dialog designer make sure the checkbox "Use Tabstops" is ON.[/blue][code]
    CString strRecord;
    CString strField1;
    CString strField2;
    CString strField3;

    strRecord = strField1 + " " + strField2 + " " + strField3;
    GetDlgItem (IDC_LIST1)->AddString (strRecord);
    [/code]
Sign In or Register to comment.