access and deleting of ListBox items
-
Hi, I have created IDC_LIST (list box) of type ClistBox and Member m_list. For Add items I am using m_list.AddString(szDir); & for reset the list I am using m_list.ResetContent(); both this are working fine. Can anyone tell me how to delete a item from list ? if I have 5 items in my list box if I have selected 4th item in the list box after pressing delete button I want that 4 item to be removed from list how to do that ?? And also I want to access all items of the list box in other functions. Regards, Parichay B.P
-
Hi, I have created IDC_LIST (list box) of type ClistBox and Member m_list. For Add items I am using m_list.AddString(szDir); & for reset the list I am using m_list.ResetContent(); both this are working fine. Can anyone tell me how to delete a item from list ? if I have 5 items in my list box if I have selected 4th item in the list box after pressing delete button I want that 4 item to be removed from list how to do that ?? And also I want to access all items of the list box in other functions. Regards, Parichay B.P
Hi parichaybp , for delete from ListBox use DeleteString
-
Hi, I have created IDC_LIST (list box) of type ClistBox and Member m_list. For Add items I am using m_list.AddString(szDir); & for reset the list I am using m_list.ResetContent(); both this are working fine. Can anyone tell me how to delete a item from list ? if I have 5 items in my list box if I have selected 4th item in the list box after pressing delete button I want that 4 item to be removed from list how to do that ?? And also I want to access all items of the list box in other functions. Regards, Parichay B.P
use DeleteString() if u want to delete an item from the list. To get the index of currently seleted item use GetCurSel()... m_list.DeleteString( m_list.GetCurSel() ); if u want to get all the items in the list ..... int nCount = m_list.GetCount(); for(int nIdx = 0;nIdx< nCount;nIdx++) { CString csText; m_list.GetText( nIdx, csText ); // u will get the text in csText } nave
-
Hi parichaybp , for delete from ListBox use DeleteString
m_list.DeleteString(); its working but i want to know how to remove the selected item?? what parameter have to passed ??? how to access the selected item and remove it?? and plz also tell how to access all the list items???
-
use DeleteString() if u want to delete an item from the list. To get the index of currently seleted item use GetCurSel()... m_list.DeleteString( m_list.GetCurSel() ); if u want to get all the items in the list ..... int nCount = m_list.GetCount(); for(int nIdx = 0;nIdx< nCount;nIdx++) { CString csText; m_list.GetText( nIdx, csText ); // u will get the text in csText } nave
Thanks both are working.
-
Hi, I have created IDC_LIST (list box) of type ClistBox and Member m_list. For Add items I am using m_list.AddString(szDir); & for reset the list I am using m_list.ResetContent(); both this are working fine. Can anyone tell me how to delete a item from list ? if I have 5 items in my list box if I have selected 4th item in the list box after pressing delete button I want that 4 item to be removed from list how to do that ?? And also I want to access all items of the list box in other functions. Regards, Parichay B.P
///////This example for Delete/Insert / read and count And Create //But you dont need to create list becuase you have control in your form CListBox m_List2; m_List2.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,100,100),this,1); m_List2.AddString("1"); m_List2.AddString("2"); m_List2.AddString("3"); m_List2.AddString("4"); //For Delete from ListBox m_List2.DeleteString(0);//Delete 1//m_List2.GetCurSel() //////For GetItems CString Str,temp,Str2,Str3; CStringArray m_String; for(int i = 0;i< m_List2.GetCount();i++) { m_List2.GetText( i, temp); Str.Insert(0,"\\"+temp);//insert in location 0 Str3.Insert(Str3.GetLength(),"\\"+temp);//insert in location end Str2=Str2+"\\"+temp;//insert 1\2\3 m_String.Add(temp);//insert to array }