v
Not logged inv
SearchAsk a QuestionReport an IssueMake a SuggestionMy Questions and Issues
Issue Details
Find By ID

How to make the FocusedRow and DetailRow coincide

Issue Details

Log in to Track Changes or Edit
Q230606
Question
Donn Edwards
Yes
Processed
Answered
.NET
ASPxGridView and Editors Suite
9.2.5
Windows XP
Microsoft Visual Studio 2008
10/2/2009 6:00:09 PM
-> Created by Donn Edwards 9/18/2009 7:32:09 PM

Attachment: WebSite.zip (1782 bytes)

I refer to S30339 and example E13

If I change E13's code (see attachment) from
          <dxwgv:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" DataSourceID="AccessDataSource1" KeyFieldName="CustomerID">

to
          <dxwgv:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" DataSourceID="AccessDataSource1" KeyFieldName="CustomerID">
          <SettingsBehavior AllowFocusedRow="True" />
               <SettingsDetail AllowOnlyOneMasterRowExpanded="True" ShowDetailRow="True" />

and change the Page_Load function as follows:

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        ClearSelectionOnOtherPages()
        If grid.FocusedRowIndex = 0 Then
            grid.FocusedRowIndex = -1
        End If

     End Sub

Despite this, when I display the page, row 0 is focused, even though grid.FocusedRowIndex already has a value of -1, as suggested in S30339

I can click on the "+" button for a row and the detailrow is displayed, even though the focusedrow is a different row. I have tried various ideas to set the focus of the row where the detailedrow is displayed, without success. Please tell me how I can do this.

Please tell me how I can disable the focusedrow until a row is actually selected, if at all possible.

Finally, if I want to select and set the focus of a row that isn't on the first page, how do I do this? For example, in Northwind Traders the opening page of the Sales Order table is usually in the range 10248-10257. I would like to be able to open the AspxGridView and go directly to, say, SalesOrder #11015, which is on page 77 in my data.
How can I go there and set the selected row and the focused row to this value? I can do it by setting a filter and getting just the single row, but when I clear the filter the focus is lost and it reverts back to the first record. It's just too easy to get lost in a gazillion records this way.

Any suggestions will be gratefully accepted. I think ASPxGridView is awesome, and thanks once again for all the help you guys have provided.

<- Reviewed by DevExpress Team 9/21/2009 6:50:43 AM
<- Processed (Answered) by DevExpress Team 9/21/2009 8:38:35 AM

Attachment: Q230606.zip (368776 bytes)

Hi Donn,

To remove focus, you need to use SetFocusedRowIndex Client-Side Method. I've attached a sample project that demonstrates how you can set focus to a detail row, which gets expanded, or remove focus otherwise. You can set selection for the grid on any page using the key value of the row using ASPxGridView.Selection.SelectRowByKey Method. The FocusedRow property reflects grid's representative state - an element can't be focused if it's not displayed (e.g. it's on another page). So this behavior is by design.

With best regards,
Ivan N.

-> Reactivated by Donn Edwards 9/21/2009 5:58:16 PM

Thanks once again. I will use the example provided. You guys are amazing.

<- Processed (Customer Closed) by Donn Edwards 9/21/2009 5:58:30 PM

Thanks

-> Reactivated by Donn Edwards 9/25/2009 10:00:58 PM

Attachment: WebSite129.zip (4259 bytes)

Thanks for the sample code but I had to modify it a bit, as per attached version.

Now can you please help me with selecting data, if this is at all possible.

I have created
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        grid.Selection.UnselectAll()
        grid.Selection.SetSelectionByKey(27, True)
    End Sub

This selects a row on page 2. I have looked everywhere but I can't figure out how to find the page number of the selected row, and then how to select that page programatically.

Are there methods to do this?
Thanks in advance once again.

<- Processed (Answered) by DevExpress Team 9/28/2009 10:49:51 AM

Hi Donn,

You can use the ASPxGridView.FindVisibleIndexByKeyValue Method for this purpose. The example from this help article shows how to navigate to a page that contains a row with the given key value. You can use the same approach for selection.

With best regards,
Ivan N.

-> Reactivated by Donn Edwards 9/28/2009 3:07:26 PM

Thanks once again.

I have converted the C# example to VB.NET using a code translator, and will fiddle with it until it works.

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Obtain the visible index of the required row.
        Dim rowIndex As Integer = grid.FindVisibleIndexByKeyValue("OLDWO")
        If (rowIndex < 0) Then
            Return
        End If
        If Not IsRowVisibleOnScreen(rowIndex) Then
            ' Switch to the page which contains the required row.
            GoToPage(rowIndex)
        End If
        ' Focus the required row.
        grid.FocusedRowIndex = rowIndex
    End Sub
    
    Private Function IsRowVisibleOnScreen(ByVal rowIndex As Integer) As Boolean
        Dim startIndex As Integer = (grid.PageIndex * grid.SettingsPager.PageSize)
        Dim endIndex As Integer = (startIndex + grid.SettingsPager.PageSize)
        Return ((rowIndex >= startIndex) _
                    AndAlso (rowIndex < endIndex))
    End Function
    
    Private Sub GoToPage(ByVal rowIndex As Integer)
        grid.PageIndex = (rowIndex / grid.SettingsPager.PageSize)
    End Sub

<- Processed (Answered) by DevExpress Team 9/29/2009 9:00:57 AM

Hi Donn,

If you experience any problems, don't hesitate to contact us at any moment.

With best regards,
Ivan N.

<- Processed (Customer Closed) by Donn Edwards 10/2/2009 6:00:09 PM

This is exactly what I was looking for. Thanks once again.

Log in to Track Changes or Edit

Peer-to-Peer Discussion in DevExpress Forums

No discussion on this article has been started yet.

Please login to start discussion.

v
v
Search
Searching Tips