Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - Select/Focus a single row?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Select/Focus a single row?

 Post Reply Post Reply
Author
Message
craig View Drop Down
Groupie
Groupie


Joined: 11 August 2005
Location: United States
Status: Offline
Points: 44
Post Options Post Options   Thanks (0) Thanks(0)   Quote craig Quote  Post ReplyReply Direct Link To This Post Topic: Select/Focus a single row?
    Posted: 19 April 2006 at 1:04pm
I'm a bit stumped on how I can select and set focus to a CXTPReportRecord that I just added?  Any help would be appreciated (I can submit a support ticket if that is preferable)

In my OnInitDialog method I am adding all of my records to the report control.  As I add them, I am inspecting them to determine which row should be the one that is selected (Single selection).  I store the pointer to this record and then after calling Populate() (which as I understand it will sort my records) I use the following code to set the stored record as selected/focused.  It is selecting/focusing a different record than the one I cached the pointer to though.


// pSelectedRecord is the record I just added to the
// report control that I want to set as selected and
// with focus

CXTPReportSelectedRows* pSelectedRows = m_wndSrsList.GetSelectedRows();
  if (pSelectedRows != NULL)
  {
    int nRow = pSelectedRecord->GetIndex();
    CXTPReportRows* pRows = m_wndSrsList.GetRows();
    CXTPReportRow* pRow = pRows->GetAt(nRow);
    m_wndSrsList.SetFocusedRow(pRow);
    if (pRow != NULL)
    {
      pSelectedRows->Clear();
      pSelectedRows->Add(pRow);
    }
  }

Back to Top
rmercer View Drop Down
Groupie
Groupie


Joined: 22 February 2006
Status: Offline
Points: 34
Post Options Post Options   Thanks (0) Thanks(0)   Quote rmercer Quote  Post ReplyReply Direct Link To This Post Posted: 19 April 2006 at 4:05pm

Originally posted by craig craig wrote:

I'm a bit stumped on how I can select and set focus to a CXTPReportRecord that I just added?  Any help would be appreciated (I can submit a support ticket if that is preferable)

In my OnInitDialog method I am adding all of my records to the report control.  As I add them, I am inspecting them to determine which row should be the one that is selected (Single selection).  I store the pointer to this record and then after calling Populate() (which as I understand it will sort my records) I use the following code to set the stored record as selected/focused.  It is selecting/focusing a different record than the one I cached the pointer to though.


// pSelectedRecord is the record I just added to the
// report control that I want to set as selected and
// with focus

CXTPReportSelectedRows* pSelectedRows = m_wndSrsList.GetSelectedRows();
  if (pSelectedRows != NULL)
  {
    int nRow = pSelectedRecord->GetIndex();
    CXTPReportRows* pRows = m_wndSrsList.GetRows();
    CXTPReportRow* pRow = pRows->GetAt(nRow);
    m_wndSrsList.SetFocusedRow(pRow);
    if (pRow != NULL)
    {
      pSelectedRows->Clear();
      pSelectedRows->Add(pRow);
    }
  }

Here's how I do it in my code, I also use groups so I have to expand the group too:

m_ctlCategories.Populate();

if (p_record_selected != NULL)

{

    p_rows = m_ctlCategories.GetRows();

    if (p_rows != NULL)

    {

        p_row = p_rows->Find(p_record_selected);

        if (p_row != NULL)

        {

               p_row->GetParentRow()->SetExpa nded(TRUE);

               m_ctlCategories.SetFocusedRow(p_row);

        }

}

 

 

Back to Top
craig View Drop Down
Groupie
Groupie


Joined: 11 August 2005
Location: United States
Status: Offline
Points: 44
Post Options Post Options   Thanks (0) Thanks(0)   Quote craig Quote  Post ReplyReply Direct Link To This Post Posted: 19 April 2006 at 5:55pm
Thank you that worked.

It actually appears that I was adding the record I needed to select after calling populate which is why my original code was failing.  Your code works too though, and I appreciate you taking the time to answer my question.  In fact, I didn't discover my bug until I tried applying your code.

--Craig

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.188 seconds.