CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2003
    Location
    London
    Posts
    198

    deselecting text..

    Hi:
    i am using following code
    //CTextEditor is propertypage
    //m_Editor is CEdit
    BOOL CTextEditor::OnSetActive()
    {

    m_Editor.SetWindowText(m_Text);


    return CPropertyPage::OnSetActive();
    }

    the result is that the whole text in the CEdit is selected...can someone help me how to stop selection of the text...
    thanks
    Ahmed

  2. #2
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    m_Edit.SetSel(0,0) to put the insertion mark before the text.
    m_Edit.SetSel(-1,-1) to put the insertion mark after the text.

  3. #3
    Join Date
    Jun 2003
    Posts
    16
    try it out.

    CEdit *e;
    e=(CEdit*)GetDlgItem(IDC_SEARCHTEXT);
    e->SetSel(-1,m_SEARCHTEXT.GetLength(),FALSE);

    //IDC_SEARCHTEXT => id of the edit control
    //m_SEARCHTEXT => CString variable of IDC_SEARCHTEXT
    Last edited by rdonline1; June 25th, 2003 at 05:58 AM.

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by gstercken
    m_Edit.SetSel(-1,-1) to put the insertion mark after the text.
    Are you sure that this will work? It is not mentioned in the documentation and usually I did
    Code:
    m_Edit.SetSel(m_Content.GetLength(), m_Content.GetLength())
    where 'm_Content' is an associated member variable of type 'CString' to the content of the edit control...

  5. #5
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Originally posted by Andreas Masur
    Are you sure that this will work? It is not mentioned in the documentation and usually I did...
    Yes, it works, although I must admit that it is not documented exactly like that. MSDN says:
    If the nStart parameter is 0 and the nEnd parameter is –1, all the text in the edit control is selected. If nStart is –1, any current selection is removed. The caret is placed at the end of the selection indicated by the greater of the two values nEnd and nStart.
    This always made me conclude that -1 generally means "after the last character", and in fact, it behaves like that. But I agree that using GetLength() is somewhat safer.

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by gstercken
    MSDN says:
    If the nStart parameter is 0 and the nEnd parameter is –1, all the text in the edit control is selected. If nStart is –1, any current selection is removed. The caret is placed at the end of the selection indicated by the greater of the two values nEnd and nStart.
    Well...that is the kind of fun I always have with the MSDN. The october 2001 version does not mention it the way as you have quoted for the edit control...

    From your quote it is at least clearer than what I have...

  7. #7
    Join Date
    Mar 2003
    Location
    London
    Posts
    198
    setsel is not working...
    Rather when i changed the tab order of CEdit ... now its working fine..It was the tab order creating problems..it was setting focus to CEdit when activating...
    Thanks
    AHmed

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