Skip to Content
author's profile photo Former Member
Former Member

Select a Row in a gird via Code

Hello again, pherhaps someone has an idea how i can get a solution for me issue 😊

<b>Following is happen:</b>

- I have an Textbox where a User can type in an Extendsearch for the shown Grid

- with the Text in the Textbox I go throw the Gird

- Have I found a match in the gird of the Text the User has searched I would to show the result on the Grid with highlighting the Row of the First match

<b>Today I have the logic to get throw the row to find a match:</b>

' Search for the Place of typed Key

Dim sKey As String = SBOapplication.Forms.Item(pVal.FormUID).Items.Item("txtOrtFind").Specific.Value

oSAPCI.GetItemInfo(SBOapplication.Forms.Item(pVal.FormUID))

Dim oGrid As SAPbouiCOM.Grid = SBOapplication.Forms.Item(pVal.FormUID).Items.Item("gridView").Specific

Dim sComp As String = ""

' Search throw the grid

For i As Integer = 1 To oGrid.Rows.Count

Try

' Get the Value of each Row

sComp = oGrid.DataTable.GetValue("ORT", oGrid.GetDataTableRowIndex(i))

If sComp.Substring(0, sKey.Length).ToLower = sKey.ToLower Then

' So I have found the match

' Now I would show the result on the grid

' The Row Index of the Gird is "i"

' Now there Comes the Problem, How could I select this specific Row "i" in the Grid?

End If

Catch ex As Exception

End Try

Next

Thx for your regards

Edited by: Gerald Schwarz on May 26, 2009 10:25 AM

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 26, 2009 at 02:27 PM

    Hi Gerald,

    To do you can use the SelectedRows collection and Add Method.

    You should have to go row by row and read the row position in the datatable by GetDataTableRowIndex() function.

    This sample code selects the customers from the grid loaded from ocrd table.

      Private Sub TEST()
            Dim oForm As SAPbouiCOM.Form = SBO_Application.Forms.Add("1", BoFormTypes.ft_Sizable)
            oForm.Height = 300
            oForm.Width = 300
            oForm.Visible = True
            Dim oItem As SAPbouiCOM.Item = oForm.Items.Add("3", BoFormItemTypes.it_GRID)
            oItem.Height = 200
            oItem.Width = 290
            oItem.Left = 5
            oItem.Top = 5
            Dim oGrid As SAPbouiCOM.Grid = oItem.Specific
    
            oGrid.SelectionMode = BoMatrixSelect.ms_Auto
            Dim oDatatable As SAPbouiCOM.DataTable = oForm.DataSources.DataTables.Add("OCRD")
            oDatatable.ExecuteQuery("select cardcode, cardtype, cardtype from ocrd")
            oGrid.DataTable = oDatatable
            For i As Integer = 0 To oGrid.Rows.Count - 1
                Dim ipos As Integer = oGrid.GetDataTableRowIndex(i)
                If oDatatable.GetValue("cardtype", ipos) = "C" Then
                    oGrid.Rows.SelectedRows.Add(i)
                End If
            Next
        End Sub
    

    Regards,

    J.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.