Forum Discussion

mrezahoseini's avatar
mrezahoseini
Contributor
10 years ago

search in datagrid view in TC

Hello



I would like to find a value that was inserted in datatgridview in last page, i couldn't search any value with datagridview cell.what shall i do?



please help me

7 Replies

  • i have enterd this code in my program, it didn't work."error log:"rows can not find"




    bankingWinUI = Aliases.BankingWinUI;



    tableLayoutPanel = bankingWinUI.frmUserSearch.tableLayoutPanel1;



    Grid =tableLayoutPanel.entityDataGridView1.dgvMain;



    var Driver = DDT.ExcelDriver("C:\\Add-Modireyate-Gorohha.xls", "Sheet1");



     



    RowIndex = FindRow (Grid, 3, Driver.Value(0));



    DDT.CloseDriver(Driver.Name);



    if (RowIndex >= 0)



    Grid.ClickCell (RowIndex, "F'E");



    else



    Log



     



     



     



    .Error("Row was not found.");



     



    function FindRow (Grid, ColumnId, Value)



    {



    for (var i=0; i<Grid.RowCount; i++)



     



    if (Grid.Text.OleValue(i, ColumnId) == Value){



    return i;



    }



    return -1;



     



    }



     



     



     


  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor



    function FindRow(Grid, ColumnId, Value){


    for (var i=0; i < Grid.Rows.Count; i++){


    if (Grid.wValue(i,ColumnId).OleValue == Value){


     return i;


     }

    }


    return -1;


    }

  • Thanks for your reply



    i enterd this code into my code, but the error has been



    The error is : Unable to find the object wValue(0, ColumnName).

    See Additional Information for details. 17:12:49 Normal  



    Is it ok if I ask you to help me again?





    Thank you
  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    It's hard to tell with your aliasing, but is this a .Net application you are testing?

    If so what is the ClrClassName of the object that you are passing to that function?
  • aminsaurabh's avatar
    aminsaurabh
    Occasional Contributor
    Hi , i have a VB.NET Application under test and the following code got the job done.



    Function selectcell(Grid, Columname, Value) 'select the particular cell and click that cell

      Dim i

      Dim rowindex

      rowindex = -1

      For i = 0 To Grid.wRowCount-1

        ' Check the cell value in the specified column

        If Grid.wValue(i, Columname) = Value Then

          rowindex = i  ' Row is found

        End If

      Next

      if rowindex >=0 Then

      Call Grid.ClickCell(rowindex, Columname)

      Else

      log.Error "value does not exist in the grid lookup","the value you are trying to select does not exist"

      End If

    End Function



    hope this was helpful
  • sbkeenan's avatar
    sbkeenan
    Frequent Contributor
    Hi Mina

     

    I’m not sure if you have resolved your problem – if not, you might find that the grid control has a ‘FindRow’ method built-in.   We use Developer Express grids in our application and I can use the FindRow function supplied.  If you have such a method, you should be able to write something like:

     



    var bankingWinUI = Aliases.BankingWinUI;

    var tableLayoutPanel = bankingWinUI.frmUserSearch.tableLayoutPanel1;

    var grid =tableLayoutPanel.entityDataGridView1.dgvMain;

    var Driver = DDT.ExcelDriver("C:\\Add-Modireyate-Gorohha.xls", "Sheet1");

    var rowIndex = grid.FindRow (3, Driver.Value(0));

    DDT.CloseDriver(Driver.Name);

    if (rowIndex >= 0)

       grid.ClickCell (rowIndex, "F'E");

    else

       Log.Error("Row was not found.");



     

    The above is based on your previously supplied code, but uses the built-in FindRow method, so there is no need to call a separate user-defined function in your code.  The only other recommendation I would make is that rather than specifying the column index, you can use the column heading.  I find that this serves two very useful purposes:

     



    1. Sometimes grid columns are hidden from the end user so what looks like column 3 may actually be column 5!!


     



    1. Using the column heading makes the code that much easier to follow and eliminates the need for commenting the fact that column 3 represents the <column name here> column.


     

    Hope you find this helpful.

     

    Regards

    Stephen.