예제 #1
0
        /// <summary>
        /// Updates the items for the list.
        /// </summary>
        private void RefreshItems()
        {
            // flip...
            if (this.InvokeRequired)
            {
                // flip...
                RefreshItemsDelegate d = new RefreshItemsDelegate(this.RefreshItems);
                this.Invoke(d, new object[] {});
                return;
            }

            // try...
            this.BeginUpdate();
            try
            {
                this.Items.Clear();
                if (this.HasDataSource == false)
                {
                    return;
                }

                // check...
                if (DataSourceAsICollection == null)
                {
                    throw new ArgumentNullException("DataSourceAsICollection");
                }

                // walk...
                foreach (object entity in this.DataSourceAsICollection)
                {
                    // should be displayed...
                    EntityListViewItem item = new EntityListViewItem(this, entity);
                    bool ok = false;
                    if (this.HasFilter)
                    {
                        // check...
                        foreach (ListViewItem.ListViewSubItem subItem in item.SubItems)
                        {
                            string text = subItem.Text;
                            if (text != null && text.Length > 0)
                            {
                                if (text.ToLower().IndexOf(this.Filter) != -1)
                                {
                                    ok = true;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        ok = true;
                    }

                    // add it...
                    if (ok)
                    {
                        this.Items.Add(item);
                    }
                }
            }
            finally
            {
                this.EndUpdate();
            }
        }