Multi Line ListBox
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Multi Line ListBox

  1. #1
    Join Date
    Oct 2008
    Posts
    59

    Multi Line ListBox

    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...
    Attached Images Attached Images  

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,008

    Re: Multi Line ListBox

    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.
    Victor Nijegorodov

  3. #3
    Join Date
    Oct 2008
    Posts
    59

    Re: Multi Line ListBox

    Sorry...In my appln, certain data is communicating with hardware.thats wy I have used certain assembly codes for error elimination.....Leave it...

    Can u help me for coding it...I've tried it nw..bt failing..can u sugggest any such codes...

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,008

    Re: Multi Line ListBox

    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!
    Victor Nijegorodov

  5. #5
    Join Date
    Oct 2008
    Posts
    59

    Unhappy Re: Multi Line ListBox

    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????

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,008

    Re: Multi Line ListBox

    The CArray<int,int> aryListBoxSel contains the indexes of selected items.
    Victor Nijegorodov

  7. #7
    Join Date
    Oct 2008
    Posts
    59

    Wink Re: Multi Line ListBox

    lemme try more...... n come back 2 u..thanx....

  8. #8
    Join Date
    Oct 2008
    Posts
    59

    Question Re: Multi Line ListBox

    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????

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,008

    Re: Multi Line ListBox

    Please, read the documentation (MSDN).

    PS: BTW, why did you get the arySel with the item indexes if you don't use it at all?
    Victor Nijegorodov

  10. #10
    Join Date
    Oct 2008
    Posts
    59

    Re: Multi Line ListBox

    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......... ???

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,008

    Re: Multi Line ListBox

    Please, read MSDN carefully!
    CListBox::GetSelItems

    Fills a buffer with an array of integers that specifies the item numbers of selected items in a multiple-selection list box.

    int GetSelItems(
    int nMaxItems,
    LPINT rgIndex
    ) const;

    Parameters

    nMaxItems
    Specifies the maximum number of selected items whose item numbers are to be placed in the buffer.

    rgIndex
    Specifies a long pointer to a buffer large enough for the number of integers specified by nMaxItems.
    Victor Nijegorodov

  12. #12
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: Multi Line ListBox

    and remember to delete them from the highest index downwards...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center