Search for empty string not working

Posted by: ellie.oosterhof on 6 November 2023, 2:21 am EST

  • Posted 6 November 2023, 2:21 am EST

    I have converted some old spread7 to spread.net code. In this code I search for the row in which an empty string exists (old: lngRow = grdFLItemRow.SearchCol(1, 0, .MaxRows, “”, SearchFlagsNone)

    new: grdFLItemRow.Search(1, string.Empty, false, false, true, false, 0, 0, grdFLItemRow.ActiveSheet.RowCount, 0, ref row, ref col);

    However, this always returns -1 for the row.

    But when I do in the immediate window (grdFLItemRow.ActiveSheet.Cells[1,0].Text).Equals(string.Empty) it returns true.

    (first I searched for “” , and also in the immediate window , ?grdFLItemRow.ActiveSheet.Cells[1,0].Text → “” )

    ActiveSheet =1

    Why is the row not set to 1? in the search method?

  • Posted 6 November 2023, 9:32 pm EST

    Hello Ellie,

    We, too, can observe the behavior at our end with the latest Spread 16 version, so we are discussing it with the developers.

    We will get back to you as soon as we get the updates from their end.

    [Internal Tracking ID: SPNET-34982]

    Regards,

    Prabhat Sharma.

  • Posted 12 November 2023, 11:05 pm EST

    Hello Ellie,

    As per the developers, FpSpread.Search searches for cell text. It means that an empty cell and the cell that contains empty text is same. That’s why the result is [-1, -1].

    If you want to search for cell value, you can use the following code:

                if (fpSpread1.ActiveSheet.Models.Data is DefaultSheetDataModel dataModel)
                {
                    row = dataModel.NextNonEmptyRow(-1, ExcludeContents.None);
                    while (row != -1)
                    {
                        int column = dataModel.NextNonEmptyColumnInRow(row, -1, ExcludeContents.None);
                        while (column != -1)
                        {
                            if (dataModel.GetValue(row, column) is string text && text.Length == 0)
                            {
                                //empty text
                            }
    
                            column = dataModel.NextNonEmptyColumnInRow(row, column, ExcludeContents.None);
                        }
    
                        row = dataModel.NextNonEmptyRow(row, ExcludeContents.None);
                    }
                }

    Regards,

    Prabhat Sharma.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels