none
How to Autoscroll listbox MFC CE RRS feed

  • Question

  • Have a VS2005 developed program for Win CE 5.0 device with a barcode scanner.

    With each barcode scaned I insert or add to the listbox. I need to scroll the list up when

    I reach the bottom such that I can see the last few scans.

    Any sample code or suggestions will be helpful.

     

    In "Design properties" I have "Disable noscroll FALSE" and

    "Vertical scrollbar TRUE".

     

    void CMFCPA600Dlg:Big SmileoDataExchange(CDataExchange* pDX)
    {
      CDialog:Big SmileoDataExchange(pDX);
      DDX_Control(pDX, IDC_LIST1, m_var1);
      DDX_Control(pDX, IDC_BUTTON5, m_button5);
      DDX_Control(pDX, IDC_BUTTON4, m_button4);
      DDX_Control(pDX, IDC_EDIT1, ed1);
      DDX_Text(pDX, IDC_EDIT1, ed1_str);
    }

     

    this_item = m_var1.InsertString(-1,ex);

     

    Looking forward,

    PXU

     

    Tuesday, January 29, 2008 4:29 PM

Answers

  • Hi,

     

    You could call the listbox's SetCurSel method after your call to InsertString. This selects an item in the listbox and scrolls it into view if it is not already visible. See the MSDN documentation (http://msdn2.microsoft.com/en-us/library/17s5dh70(VS.80).aspx) for further details. In fact the documentation has the following code sample which should do what you want:

     

    Code Snippet

    // Select the last item in the list box.
    int nCount = m_var1.GetCount();
    if (nCount > 0)
      m_var1.SetCurSel(nCount - 1);

     

    Hope this helps,

    Christopher Fairbairn

     

    Tuesday, January 29, 2008 11:38 PM

All replies

  • Hi,

     

    You could call the listbox's SetCurSel method after your call to InsertString. This selects an item in the listbox and scrolls it into view if it is not already visible. See the MSDN documentation (http://msdn2.microsoft.com/en-us/library/17s5dh70(VS.80).aspx) for further details. In fact the documentation has the following code sample which should do what you want:

     

    Code Snippet

    // Select the last item in the list box.
    int nCount = m_var1.GetCount();
    if (nCount > 0)
      m_var1.SetCurSel(nCount - 1);

     

    Hope this helps,

    Christopher Fairbairn

     

    Tuesday, January 29, 2008 11:38 PM
  • See you can do it by two way either Simplu use SetCurSel() method which will take index of the item to be selected in that simply put the index of last item of the List control .Second what you can do use LV_ITEM structure and can use LVIS_SELECTED macro and then put the new element in the list control.That's all you have to do.

    Thanx

    Wednesday, January 30, 2008 1:55 PM
  • Thank you, Christopher and Pintu. Problem solved.

    Regards,

    PXU

     

    Wednesday, January 30, 2008 2:40 PM