none
CEdit multiline scroll RRS feed

  • Question

  • Hello,

    I have a CEdit contains 40 lines (using CEdit's GetLineCount) but in the gui it always displays from the very first line with the vertical scroll bar at the top. How do I programmatically make the CEdit display the bottom of the text? In other words, make the vertical scroll bar down to the bottom. CEdit's LineScroll(nLine) does not do anything, where nLine is 40 or any other number. Please help.

    Regards,

    Thursday, October 13, 2005 7:46 PM

Answers

  • I was able to do this in Visual Studio 2005 by doing the following:

    -Create an MFC dialog-based app
    -Add an edit control to the main dialog
    -Set the Multiline and Vertical Scroll properties to "True"
    -Add a new button to the dialog and add a BnClicked handler that does this:

        m_editcontrol.LineScroll(m_editcontrol.GetLineCount());

    -Run the app and paste a bunch of multiline text into it.
    -Scroll the edit control to the top.
    -Click the new button.

    When I did this, the edit control scrolled to the bottom.  Is this different than what you tried?

    I hope this is helpful,

    -Ron Pihlgren
     VC++ Testing

    Friday, October 14, 2005 11:57 PM
  • Hi Ron,

    Thanks a lot for your explanation. I tried your example and it did work. My problem was I used UpdateData(FALSE) at the end of my OnInitialUpdate. Here is a sample code that shows problem:

    Inside a dialog or form's OnInitialUpdate
    where m_strEdit is the value CString map to the CEdit control (multiline) and
    m_btnEdit is the control CEdit.

    //--------------
    ....
        char temp[100];
        m_strEdit = "";
     for(int i = 0; i < 30; i++)
        {
            temp[0] = '\0';
            sprintf(temp, "Line Number#%d", i);
            m_strEdit += temp;
            m_strEdit += "\r\n";

            UpdateData(FALSE);
            m_btnEdit.LineScroll(m_btnEdit.GetLineCount());
        }

        UpdateData(FALSE); //********Caused problem
    //--------------

    The solution is to remove the last UpdateData(FALSE). I guess UpdateData(FALSE) transfers m_strEdit to the gui control through DDX and the multiline position is lost in the process unless another LineScroll is called. Thanks again.

    Regards,

      -Mountain_loin


    Monday, October 17, 2005 5:24 PM

All replies

  • I was able to do this in Visual Studio 2005 by doing the following:

    -Create an MFC dialog-based app
    -Add an edit control to the main dialog
    -Set the Multiline and Vertical Scroll properties to "True"
    -Add a new button to the dialog and add a BnClicked handler that does this:

        m_editcontrol.LineScroll(m_editcontrol.GetLineCount());

    -Run the app and paste a bunch of multiline text into it.
    -Scroll the edit control to the top.
    -Click the new button.

    When I did this, the edit control scrolled to the bottom.  Is this different than what you tried?

    I hope this is helpful,

    -Ron Pihlgren
     VC++ Testing

    Friday, October 14, 2005 11:57 PM
  • Hi Ron,

    Thanks a lot for your explanation. I tried your example and it did work. My problem was I used UpdateData(FALSE) at the end of my OnInitialUpdate. Here is a sample code that shows problem:

    Inside a dialog or form's OnInitialUpdate
    where m_strEdit is the value CString map to the CEdit control (multiline) and
    m_btnEdit is the control CEdit.

    //--------------
    ....
        char temp[100];
        m_strEdit = "";
     for(int i = 0; i < 30; i++)
        {
            temp[0] = '\0';
            sprintf(temp, "Line Number#%d", i);
            m_strEdit += temp;
            m_strEdit += "\r\n";

            UpdateData(FALSE);
            m_btnEdit.LineScroll(m_btnEdit.GetLineCount());
        }

        UpdateData(FALSE); //********Caused problem
    //--------------

    The solution is to remove the last UpdateData(FALSE). I guess UpdateData(FALSE) transfers m_strEdit to the gui control through DDX and the multiline position is lost in the process unless another LineScroll is called. Thanks again.

    Regards,

      -Mountain_loin


    Monday, October 17, 2005 5:24 PM