Print Page | Close Window

Select/Focus a single row?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=4030
Printed Date: 21 November 2024 at 4:40pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Select/Focus a single row?
Posted By: craig
Subject: Select/Focus a single row?
Date 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);
    }
  }




Replies:
Posted By: rmercer
Date 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);

        }

}

 

 



Posted By: craig
Date 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




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net