CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2008
    Posts
    59

    Aligning the various CStrings in a List Box

    I am having 2 text boxes and a combo box. The dats from thiese folders are assigned to a listbox.
    The code for this add operation is
    Code:
    void CNewSerialPrintDlg::OnBnClickedButtonPmenter()
    {
    	// TODO: Add your control notification handler code here
    	CString PType,Pname,CPNo;
        CStringList parList;
    	m_PNoctrl.GetWindowText(CPNo);
    
    	m_pnamectrl.GetWindowText(Pname);
    	iSelType=m_ptypectrl.GetCurSel();
    	switch(iSelType)
    	{
    		case 0:
    			PType="HEX";
    			break;
    		case 1:
    			PType="FLOAT";
    			break;
    		case 2:
    			PType="UINT";
    			break;
    		default:
    			break;
    	}
    	if((Pname=="")||(iSelType==CB_ERR))
    	{
    		AfxMessageBox(_T("Data insufficient!Try again"));
    		return;
    	}
    	ParNoName=CPNo +_T("  ")+ Pname;  
    	ParSel=ParNoName+_T("      ")+ PType; 
    	parList.AddTail(ParSel);
    
    	unsigned int hrt=m_parameterlist.GetCurSel();   //CListBox m_parameterlist
    	m_parameterlist.ResetContent();
    	if(parList.IsEmpty()==0)
    	{
    		for(POSITION pos=parList.GetHeadPosition();pos!=NULL;)
    		{
    			CString Par_disp= parList.GetNext(pos);
    			m_parameterlist.AddString(Par_disp);
    		}
    	}
    	m_btndatarcv.EnableWindow(TRUE);
    	m_btnSvFl.EnableWindow(TRUE);	
    }
    the output getting has attached.

    my requirement is: Can I align certain tabspace in between each of these CStrings. Means instead of the space in between the CStrings, Can I use a tab space or anything...which could be better for a nice view.......(Sorry,can't use database here)........thank u/.
    Attached Images Attached Images  

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Aligning the various CStrings in a List Box

    Replace space with tab:
    +_T("\t") instead of _T(" ");

    Or use ListView in report mode instead of listbox.

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Aligning the various CStrings in a List Box

    Quote Originally Posted by Alex F View Post
    Or use ListView in report mode instead of listbox.
    +1 If you take the time to learn a listview, it will allow you to do more advanced things later like column sorting, column alignment, etc.

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Aligning the various CStrings in a List Box

    Quote Originally Posted by Alex F View Post
    Replace space with tab:
    +_T("\t") instead of _T(" ");

    Or use ListView in report mode instead of listbox.
    Yes, but that would require an additional fixed size font, otherwise it would be pointless, because different characters have different widths.

    Though I also stand with Arjay and recommend a list view instead, it is possible to have a list box with multiple columns. Here is an article with a sample: http://www.codeproject.com/KB/cpp/mclb.aspx.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Aligning the various CStrings in a List Box

    Quote Originally Posted by cilu View Post
    Yes, but that would require an additional fixed size font, otherwise it would be pointless, because different characters have different widths.

    Though I also stand with Arjay and recommend a list view instead, it is possible to have a list box with multiple columns. Here is an article with a sample: http://www.codeproject.com/KB/cpp/mclb.aspx.
    I agree that the list control is better suited to the task, but the tabs will give him the appearance of columns, even though the individual characters may not line up exactly.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured