My application is developig in VC++ 2008. I have a List Box. Where I am Loading some Text data from a text file. After Loaded the listBox is as show in the attached figure :
I have used it as a SINGLE SELECTION List Box. Here I would like to change as MULTILINE SELECTION so as to delete the selected List BOX datas.
For the Single Line Delete operation I have written the following code.
Code:
CListBox m_parameterlist;
unsigned int len = m_parameterlist.GetCurSel();
if(len==LB_ERR)
{
len = m_parameterlist.GetCount();
len = len-1;
}
int current = m_parameterlist.DeleteString(len);
int newcnt = m_parameterlist.GetCount();
CString str;
if(newcnt>0)
{
for(int i = 0;i < newcnt;i++)
{
m_parameterlist.GetText( i, str );
}
}
else
_asm nop;
This has worked. The single line deleted and the remaining datas listed on ListBx But Now the User requirment got modified. I have changed the property to MULTILINE SELCTION. But the coding is confused.... Can u help me plz...
1. Your code is a little strange: what for are you using
Code:
_asm nop;
2. To delete items in a listbox with multi-selection you have to call CListBox::GetSelItems , then sort the item indexes in a buffer and then delete selected items in a loop beginning from the max index.
Start with the example from MSDN article CListBox::GetSelItems
I hope, a simple sorting algorithm won't be a problem for a programmer being able to program with Assembler for hardware!
Assembler is extremely different from GUI concepts..... While working on GUI based pgms,I have struggled several times n the CodeGurus like u helped me a lot... tats wy am here for getti ng it. I've tried the same example.. It gets the Count of Total selected items.But How to select particular indices for Delete????
As like the above said procedure..I've written the code as
Code:
int iTot = m_parameterlist.GetCount();
iTot-=1;
int len=m_parameterlist.GetSelCount();
CArray<int,int> arySel;
arySel.SetSize(len);
int newval=m_parameterlist.GetSelItems(len, arySel.GetData());
int iNew=iTot-len;
for(int i=0;i<=len;i++)
{
int current = m_parameterlist.DeleteString(i);
}
It deletes data..But not in order...Having some bugs...... Can anybody help to fix it????
Your question makes rethinking on me..
Bt after several try & error....... I reached here... n copied it here....
Ok.. So 1) how do I delete the exact Selected indexes....?
2)The return of . newval gets the Total Count of selected lines......!!!!!
got the logic..bt stucks some where......... ???
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.