Set focus on a cell

I wrote a small piece of code that would help select individual cells in a CListCtrl. This is not supported currently by the MFC.

When the user clicks on the cell in the CListCtrl it draws a rect. around that cell indicating that is the cell selected by the user. This might not be the best solution but a work around if anyone would like to use this.

//Individual cell selection in CLIstCtrl
CListCtrl::OnClick(...)
{
    int column;
    CRect m_rect;
    //the function below is provided in CListCtrl inPlace editing
    int index = GetRowColumnIndex(point, &column);
    if(index == -1)return;
    int offset = 0;
    for(int i = 0; i < column; i++)
      offset += GetColumnWidth(i);
    //Get the rectangle of the label and the icon
    GetItemRect(index, &m_rect, LVIR_BOUNDS);
    m_rect.left += offset + 4;
    //Get the columnWidth of the selected column
    m_rect.right = m_rect.left + GetColumnWidth(column);
    Update(index);
    CClientDC dc(this);    //this is the pointer of the current view
    dc.DrawFocusRect(m_rect);
}



Comments

  • Hover for Subitems

    Posted by Legacy on 08/12/2002 12:00am

    Originally posted by: Bharathy

    Does anyone know if there is hover selection for subitems?

    Reply
  • GetRowColumnIndex???

    Posted by Legacy on 05/02/2002 12:00am

    Originally posted by: Luke Clemens

    ummmm... where's that come from??

    Reply
  • What GetRowColumnIndex()????

    Posted by Legacy on 03/07/2002 12:00am

    Originally posted by: John

    There's no such function inside CListCtrl. Could you post the code if it's your custom function also?

    Reply
  • How to select and deselect individual cells?

    Posted by Legacy on 06/07/1999 12:00am

    Originally posted by: Srinivasu Achalla

    Your code is interesting but if you can provide code to select (the way items are selected) and deselct randomly clicked subitems, then it would be very good.

    Thanks in advance.

    Reply
  • A MFC version?

    Posted by Legacy on 05/12/1999 12:00am

    Originally posted by: xyjiang

    Does anyone have a MFC version of this?
    

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Agile methodologies give development and test teams the ability to build software at a faster rate than ever before. Combining DevOps with hybrid cloud architectures give teams not just the principles, but also the technology necessary to achieve their goals. By combining hybrid cloud and DevOps: IT departments maintain control, visibility, and security Dev/test teams remain agile and collaborative Organizational barriers are broken down Innovation and automation can thrive Download this white paper to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds