Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Report Control
  New Posts New Posts RSS Feed - Programmatically selecting a row
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Programmatically selecting a row

 Post Reply Post Reply
Author
Message
John31 View Drop Down
Groupie
Groupie
Avatar

Joined: 08 December 2005
Location: United States
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote John31 Quote  Post ReplyReply Direct Link To This Post Topic: Programmatically selecting a row
    Posted: 02 February 2006 at 1:57pm

Is it possible to select a row programmatically? 

For example:

The user is looking a record that is near the bottom of the list and has scrolled to get there.  The user deletes this record.  I can get the view to stay the same by restoring the TopRowIndex to the value it was before the Populate routine.  However, if the user hits an arrow key the rc jumps to the top of the list.  I have tried the following but it does not work as the row selected value goes back to false.

 

Any Ideas?

lTopIndex = RC1.TopRowIndex

' loop through all report records
For Each oRec In RC1.Records
    If InStr(1, sRecID, oRec.Item(COL_RECID).Value) Then
        Set oRow = RC1.Rows.FindRow(oRec).NextSiblingRow
        RC1.Records. RemoveAt oRec.Index
    End If
Next
                                   
RC1.Populate
RC1.TopRowIndex = lTopIndex
If Not oRow Is Nothing Then
    oRow.Selected = True
End If

 

 

Regards

John Layton
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18052
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 02 February 2006 at 2:24pm
Try setting the ReportControl.FocusedRow
Back to Top
John31 View Drop Down
Groupie
Groupie
Avatar

Joined: 08 December 2005
Location: United States
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote John31 Quote  Post ReplyReply Direct Link To This Post Posted: 02 February 2006 at 2:30pm

Mario

Did you mean FocusedRow?  This does not highlight the record either.  Any other ideas?

 

Regards

John Layton
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18052
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 02 February 2006 at 2:39pm
I just tried this:

Set wndReportControl.FocusedRow = wndReportControl.Rows(8)

and it both focuses and selects the row.  Is this not what you want?
Back to Top
John31 View Drop Down
Groupie
Groupie
Avatar

Joined: 08 December 2005
Location: United States
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote John31 Quote  Post ReplyReply Direct Link To This Post Posted: 02 February 2006 at 2:57pm

I got this to work some of the time.  Here is my dilemma, I think.

The records in the ReportControl are pulled from a DB and then sorted various ways depending on user input.  I then send a command to my server using the record id for each selected column to delete.  When I get the server response it sends me back list of records that it has deleted which is the sRecID string in the code above. 

I have no problem finding the records to delete using the code above. Finding the relative row to set focus back to is what the problem is.  I can store the last index of the last removed record and then find this row.  However, given that the ReportRows are sorted there is no guarantee that the row associated with the last index -1 is near the row that was just deleted. 

Does this make sense or am I confusing everyone.

 

 

 

 

 

Regards

John Layton
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18052
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 02 February 2006 at 3:01pm
Maybe you should use ReportRows.FindRow method to find the Row, then get its index.  You should get the Row index and not the Record index ans the Record index will remain the same.
Back to Top
John31 View Drop Down
Groupie
Groupie
Avatar

Joined: 08 December 2005
Location: United States
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote John31 Quote  Post ReplyReply Direct Link To This Post Posted: 02 February 2006 at 3:20pm

I think I figured a faster way to do it but I need to know if I can LOCK the report control so they cannot click anything else until the process is complete?  Is there a way to do this?

 

 

Regards

John Layton
Back to Top
John31 View Drop Down
Groupie
Groupie
Avatar

Joined: 08 December 2005
Location: United States
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote John31 Quote  Post ReplyReply Direct Link To This Post Posted: 02 February 2006 at 3:33pm

This works great if the user has not selected another record between delete and the server reply

 

' get the current top row to use later
lTopIndex = RC1.TopRowIndex
' set the last index to highest possible value
lLastIndex = RC1.Rows.Count
' check to see how many rows are selected
If RC1.SelectedRows.Count = 1 Then
    If RC1.SelectedRows(0).GroupRow Then
        ' loop through all child rows for this group
        For Each oRow In RC1.SelectedRows(0).Childs
             ' make sure the recid is one that actually got deleted
             If InStr(1, sRecID, oRow.Record.Item(COL_RECID).Value) Then
                 ' adjust the last row index if needed
                 If oRow.Index < lLastIndex Then lLastIndex = oRow.Index
                 ' remove the record
                 RC1.Records.RemoveAt oRow.Record.Index
             End If
        Next
    Else
        ' since this is a single row just set and delete
        Set oRow = RC1.SelectedRows(0)
        ' make sure the recid is one that actually got deleted
        If InStr(1, sRecID, oRow.Record.Item(COL_RECID).Value) Then
             ' adjust the last row index if needed
             If oRow.Index < lLastIndex Then lLastIndex = oRow.Index
             ' remove the record
             RC1.Records.RemoveAt oRow.Record.Index
        End If
    End If
Else
    ' loop through all selected records
    For Each oRow In RC1.SelectedRows
        ' make sure the recid is one that actually got deleted
        If InStr(1, sRecID, oRow.Record.Item(COL_RECID).Value) Then
             ' adjust the last row index if needed
             If oRow.Index < lLastIndex Then lLastIndex = oRow.Index
             ' remove the record
             RC1.Records.RemoveAt oRow.Record.Index
        End If
    Next
End If
' repopulate the control
RC1.Populate
' set the top index back to what it was
RC1.TopRowIndex = lTopIndex
' correct the last index as needed
If lLastIndex > RC1.Rows.Count Then
    lLastIndex = RC1.Rows.Count - 1
ElseIf lLastIndex > 1 Then
    lLastIndex = lLastIndex - 1
End If
' get the row we want to set focus on
Set oNextRow = RC1.Rows(lLastIndex)
' make sure it exists and set focus
If Not oNextRow Is Nothing Then Set RC1.FocusedRow = oNextRow

Regards

John Layton
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18052
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 03 February 2006 at 11:48am
Maybe you can first delete the record from your database, then after the delete is finished you can delete it from the ReportControl.
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.063 seconds.