For loop through DataTable rows is very slow in Windows Application

Last Reply 2 months ago By dharmendr

Posted 2 months ago

I have table item and i have create for each item button in the container panel and create text box for search on item that if the button text contain the searched text set visible true else false and it work but it's really slow and look like there an issue in my application.

So there faster way to search on the item [button]

When select category get category items and create for each item button in Itemspanel but it really slow.

                DataRow[] rows = itemsData.Select("catID = '" + catID + "'");
                if(rows != null)
                {
                    foreach (DataRow row in rows)
                    {
                        Button btn = new Button();
                        btn.Text = row["itemName"].ToString();
                        btn.Name = "item_" + row["itemID"].ToString();
                        btn.Height = 50;
                        btn.Width = 120;
                        btn.BackColor = Color.FromArgb(186, 185, 234);
                        btn.Click += (s, e) =>
                        {
                            
                        };
                        ItemsPanel.Controls.Add(btn);
                    }
                }

 

 

Posted 2 months ago

The code doesn't have any issue.

The slow might be due to large no of record present in the DataRow array as loop is exacuted through all the records present in it.

You can't do much for this.