Discussion:
How to update the list box control with text
(too old to reply)
Mujtaba
2004-08-18 12:26:33 UTC
Permalink
hi

i am woking with ListBox control in VC++, where i have to update the
data in listbox control gradually,means some is added to listbox,
after some time next text added to list box and so on.

could anybody plz help me out.

Mujtaba
Alni
2004-08-18 13:47:56 UTC
Permalink
Bonjour,
Post by Mujtaba
hi
i am woking with ListBox control in VC++, where i have to update the
data in listbox control gradually,means some is added to listbox,
after some time next text added to list box and so on.
could anybody plz help me out.
Mujtaba
CListBox m_MyListBoxCtl;

m_MyListBoxCtl.AddString("New Text");

No ?
Mujtaba
2004-08-19 04:56:21 UTC
Permalink
Post by Alni
Bonjour,
Post by Mujtaba
hi
i am woking with ListBox control in VC++, where i have to update the
data in listbox control gradually,means some is added to listbox,
after some time next text added to list box and so on.
could anybody plz help me out.
Mujtaba
CListBox m_MyListBoxCtl;
m_MyListBoxCtl.AddString("New Text");
No ?
Hi
thanx for your reply
Actually i m asking about "i have added one string to listbox, now
after two second new string added to next line and so on", how to do
this.

i have written a function...code

void CTapiTestDlg::UpdateStatus(CString str)
{


m_listvar.AddString(str);

::Sleep(2000);

UpdateData(TRUE);


}


but its out will print at same time in listbox, how can i control this
means one after another with pause.

Hope u understand this problem and would reply..

Mujtaba
Alni
2004-08-19 08:53:15 UTC
Permalink
Bonjour,
Post by Mujtaba
Hi
thanx for your reply
Actually i m asking about "i have added one string to listbox, now
after two second new string added to next line and so on", how to do
this.
m_listvar.AddString(str);
::Sleep(2000);
UpdateData(TRUE);
but its out will print at same time in listbox, how can i control this
means one after another with pause.
What about using UpdateWindow() instead of UpdateData() :

m_listvar.AddString(str);
UpdateWindow();
::Sleep(2000);

UpdateData means exchange data contents between displayed controls and
member variables.
When you spécify true it means you want to replace the variable content
by whatever the user has put in the control.

Tom Serface
2004-08-18 23:32:00 UTC
Permalink
Like Alni says, you can use AddString to add something to a listbox whenever
you'd like. You may have t refresh the control window. Also, you can use
DeleteString to remove a string. One problem with list boxes is that they
don't automatically update the width so if you add a new item that is wider
than the list is you don't automatically get a horizontal scroll bar. You
can address this by checking each item as it is added and adjusting the
extent for the listbox.

Something like:

int oldwidth = m_ListBox->GetHorizontalExtent();
CDC* pDC = m_ListBox->GetWindowDC();
if (pDC) {
int newwidth = pDC->GetTextExtent((const char*)csStringImAdding,
csStringImAdding.GetLength()).cx;
m_ListBox->ReleaseDC(pDC);
if (newwidth > oldwidth) {
m_ListBox->SetHorizontalExtent(newwidth);
}
}

Joe Newcomer has more info on his website about this stuff:

http://www.flounder.com/hscroll.htm

All of that said, I mostly use ListCtrl's these days for even one line
lists. There is way more control and they are not difficult to use.

Tom
Post by Mujtaba
hi
i am woking with ListBox control in VC++, where i have to update the
data in listbox control gradually,means some is added to listbox,
after some time next text added to list box and so on.
could anybody plz help me out.
Mujtaba
Continue reading on narkive:
Loading...