I have developed a GUI where in I need to update some(4) parameters in a ListBox.I am usind the following code to do this.

CString tmp;
tmp.Format("%4d %4d %4d",a,b,c);
 listBx.AddString(tmp);

a,b and c are integers.listBx gets updated every 1 sec.
But I am not getting the output in a formatted manner.
Suppose if a is variable between 2 digit and 4 digit numbers the entire string gets distrubed.both b and c columns move left or right depending upon no, of digits in a.
How can this be solved.
Thanks in advance

use "%-4d" to left-justify the number in the field. Probably what you are seeing is the number right-justified.

Thanks,
But I tried even that.but in vain.When I am printing that to the console I can see the alignment but when I convert (Format) it to CString I am missing the alignment.Could there be any other fix...

Items in a list box are not generally displayed in a fixed width font. So the length of the string will vary with different numbers, even though the number of characters is constant.
You could modify the list box to use a fixed font, though you might not find that easy and it isn't always desirable to see fixed fonts on GUIs.
A better solution would be to use a list control with 3 columns instead of a simple list box. The numbers will then be aligned by the control.

commented: Good suggestion :) +36
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.