Searching Row for Text String

Posted by: mark on 25 May 2023, 7:56 pm EST

  • Posted 25 May 2023, 7:56 pm EST - Updated 25 May 2023, 8:01 pm EST

    Hi, I am trying to limit the row is display in my form which only contain a specific text string “Rolling Cash” but I cannot get it to work.

    Any advise would be most appreciated.

    Here is my code

    Thanks

    [code]

    var tbodyNodes = document.DocumentNode.SelectNodes(“//tbody[@class=‘yui-dt-data’]”);

    if (tbodyNodes != null && tbodyNodes.Count > 1)

    {

    HtmlNode secondTbodyNode = tbodyNodes[2];

                    if (secondTbodyNode.InnerLength > 0)
                    {
    
    
                        foreach (HtmlNode row in secondTbodyNode.SelectNodes("tr"))
                        {
    
    
                           * if (dataTable.Rows.Contains = ("Rolling Cash"))*
                            {
                                HtmlNodeCollection cells = row.SelectNodes("td");
                                dataTable.Rows.Add(cells[0].InnerText, cells[1].InnerText, cells[2].InnerText, cells[3].InnerText, cells[4].InnerText, cells[5].InnerText, cells[6].InnerText, cells[7].InnerText, cells[8].InnerText, cells[9].InnerText);
                            }
                        }
                    }
                    else
                    {
    
                        dataTable.Rows.Add("", "", "", "", "", "", "", "");
                    }
                }
    
                OpenOrder.DataSource = dataTable;
    
    
                return true;
            }[/code]
    
  • Posted 28 May 2023, 9:39 pm EST

    Hi Mark,

    Could you please let us know which C1 control/component are you using in your project? and of which version?

    Also, let us know the technology/platform (like WinForms, WPF, etc) on which you are developing your application. It would be really helpful if you could also provide a small sample project, so we can reproduce the issue on our end and assist you better.

    Thanks, and Best Regards,

    Kartik

  • Posted 29 May 2023, 4:07 am EST - Updated 29 May 2023, 4:15 am EST

    Hi, Sorry for my initial post lacking for lacking so little detail.

    My code is VS 2023 C#, the C1 control component is C1.Win.C1InputPanel.4.5.2 on Winforms.

    I am currently just started a demo for your software

    The error I am getting from my code is:

    Error CS1656 Cannot assign to ‘Contains’ because it is a ‘method group’

    I am struggling to find a suitable solution, I am trying to limit the row I display in my form too one which only contain a specific text string “UK 100 - Rolling Cash”

    I have included a screenshot of the form I have coded.

    Here is a small sample of my code if you require a larger one or further information please let me know

    Many Thanks.

    [code] public bool loadOrder()

    {

    try

    {

                dataTable = new DataTable();
    
                // Add columns to the DataTable
                dataTable.Columns.Add("Market", typeof(string));
                dataTable.Columns.Add("Amount", typeof(string));
                dataTable.Columns.Add("Stop", typeof(string));
                dataTable.Columns.Add("Limit", typeof(string));
                dataTable.Columns.Add("Hedging", typeof(string));
                dataTable.Columns.Add("IF.D Stop", typeof(string));
                dataTable.Columns.Add("IF.D Limit", typeof(string));
                dataTable.Columns.Add("Period", typeof(string));
                dataTable.Columns.Add("Current Price", typeof(string));
                dataTable.Columns.Add("Order Placed", typeof(string));
    
    
    
    
                string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "order.html");
                HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                document.Load(filePath, Encoding.UTF8);
    
    
                var tbodyNodes = document.DocumentNode.SelectNodes("//tbody[@class='yui-dt-data']");
                if (tbodyNodes != null && tbodyNodes.Count > 1)
                {
                    HtmlNode secondTbodyNode = tbodyNodes[2];
                    // Loop through the rows in the tbody
    
                    if (secondTbodyNode.InnerLength > 0)
                    {
    
    
                        foreach (HtmlNode row in secondTbodyNode.SelectNodes("tr"))
                        {
    
    
                            if (dataTable.Rows = ("UK 100 - Rolling Cash"))
                            {
                                HtmlNodeCollection cells = row.SelectNodes("td");
                                dataTable.Rows.Add(cells[0].InnerText, cells[1].InnerText, cells[2].InnerText, cells[3].InnerText, cells[4].InnerText, cells[5].InnerText, cells[6].InnerText, cells[7].InnerText, cells[8].InnerText, cells[9].InnerText);
                            }
                        }
                    }
                    else
                    {
    
                        dataTable.Rows.Add("", "", "", "", "", "", "", "");
                    }
                }
    
                OpenOrder.DataSource = dataTable;
    
    
                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return false;
            }
        }[/code]
    

  • Posted 29 May 2023, 7:35 pm EST

    Hi Mark,

    In the code that you shared, we could not clearly understand where are you actually using the C1InputPanel. Also, there are a few mistakes in your C# code that are causing the errors that you mentioned.

    According to our interpretation of your implementation, you are retrieving rows from an HTML table and putting them in a DataTable, but only for rows with a column value of “UK 100 - Rolling Cash”. We have created a small sample project showing the same. The DataTable created in the sample project is then used in our C1FlexGrid control.

    Attachment: GetDataFromHtml.zip

    If you are facing any other issues with using any of the C1 controls/components, you can let us know.

    Best Regards,

    Kartik

Need extra support?

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

Learn More

Forum Channels