/// <summary> /// this methods sorts the items to put the best match on top and then filter it with modelFilter /// </summary> private void ApplyFilter() { if (_initialObjectsList == null || _initialObjectsList.Count == 0) { return; } // save position in the list var curPos = new Point(fastOLV.SelectedIndex, fastOLV.TopItemIndex); // apply filter to each item in the list then set the list try { _initialObjectsList.ForEach(data => data.FilterApply(_filterByText)); } catch (Exception e) { if (!(e is NullReferenceException)) { ErrorHandler.LogError(e); } } if (!_isFiltering) { fastOLV.SetObjects(_initialObjectsList); } else { fastOLV.SetObjects(_initialObjectsList.OrderBy(data => data.FilterDispertionLevel).ToList()); } // display as tree or flat list? ((FilteredItemTreeRenderer)fastOLV.DefaultRenderer).DoNotDrawTree = (Config.Instance.CodeExplorerSortingType == SortingType.Unsorted) || _isFiltering; // apply the filter, need to match the filter + need to be an active type (Selector button activated) fastOLV.ModelFilter = new ModelFilter(FilterPredicate); // update total items TotalItems = ((ArrayList)fastOLV.FilteredObjects).Count; // reposition the cursor in the list if (TotalItems > 0) { fastOLV.SelectedIndex = Math.Max(0, Math.Min(curPos.X, TotalItems - 1)); try { fastOLV.TopItemIndex = Math.Max(0, Math.Min(curPos.Y, TotalItems - 1)); } catch (Exception) { // ignored } } }
public static void UpdateFOLV(ref FastObjectListView olv, IEnumerable Collection, bool ResizeCols = false) { olv.Freeze(); try { olv.ClearObjects(); olv.SetObjects(Collection, true); //update column size only if did not restore folv state file or forced if (olv.Tag == null || ResizeCols) { olv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); } if (olv.Items.Count == 0) { olv.EmptyListMsg = "Empty"; } } catch (Exception ex) { Global.Log("Error: " + Global.ExMsg(ex)); } finally { olv.Unfreeze(); } }
private void GetData(FastObjectListView olv) { try { olv.BeginUpdate(); olv.SetObjects(SimcList); olv.EndUpdate(); olv.Enabled = olv.Items.Count > 0; lblRecord.Text = "0 z " + olv.Items.Count; } catch (Exception) { throw; } }
public static void UpdateFOLV(FastObjectListView olv, IList objs, bool Follow = false, ColumnHeaderAutoResizeStyle ResizeColsStyle = ColumnHeaderAutoResizeStyle.None, bool FullRefresh = false, bool UseSelected = false, object SelectObject = null, bool ForcedSelection = false, [CallerMemberName()] string memberName = null) { Global_GUI.InvokeIFRequired(olv, () => { try { int oldcnt = olv.Items.Count; if (oldcnt == 0) { olv.EmptyListMsg = "Loading..."; } //Debug.Print($"{DateTime.Now} - {memberName} > UpdateFOLV: {objs.Count} items, Follow={Follow}"); olv.Freeze(); //accessed from another thread if (FullRefresh) { //olv.ClearCachedInfo(); //olv.ClearObjects(); } if (FullRefresh || olv.Items.Count == 0) //full refresh of new objects { olv.SetObjects(objs, true); } else { olv.AddObjects(objs); //minimize list changes } if (olv.Items.Count > 0) { if (Follow) { if (SelectObject != null && UseSelected) { //use the given object as selected olv.SelectedObject = SelectObject; //olv.Items.Count - 1; } else if (SelectObject == null && UseSelected && olv.IsFiltering && olv.GetItemCount() > 0) { //use the last filtered object as the selected object olv.SelectedObject = olv.FilteredObjects.Cast <object>().Last(); } else if (!olv.IsFiltering) { //just use the last object given to us olv.SelectedObject = objs[objs.Count - 1]; //olv.Items.Count - 1; } if (olv.SelectedObject != null) { olv.EnsureModelVisible(olv.SelectedObject); } } else { //only select something if nothing is already selected if (SelectObject != null && (ForcedSelection || (UseSelected && olv.SelectedObject == null))) { //use the given object as selected olv.SelectedObject = SelectObject; //olv.Items.Count - 1; olv.EnsureModelVisible(olv.SelectedObject); } //else if (SelectObject == null && UseSelected && olv.IsFiltering && olv.GetItemCount() > 0) //{ // //use the last filtered object as the selected object // olv.SelectedObject = olv.FilteredObjects.Cast<object>().First(); //} //else if (!olv.IsFiltering && UseSelected) //{ // //just use the last object given to us // olv.SelectedObject = objs[0]; //olv.Items.Count - 1; //} } //update column size only if did not restore folv state file or forced if (olv.Tag == null) { olv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); olv.Tag = "resizedcols"; } else if (ResizeColsStyle != ColumnHeaderAutoResizeStyle.None) { olv.AutoResizeColumns(ResizeColsStyle); olv.Tag = "resizedcols"; } } else { olv.EmptyListMsg = "Empty"; } } catch (Exception ex) { Log("Error: " + ex.Msg()); } finally { olv.Unfreeze(); if (FullRefresh) { olv.Refresh(); } } }); }
public Form1() { InitializeComponent(); _listview = new FastObjectListView(); olvColumnId = new OLVColumn(); olvColumnSent = new OLVColumn(); olvColumnRec = new OLVColumn(); olvColumnState = new OLVColumn(); olvColumnIp = new OLVColumn(); olvColumnAddress = new OLVColumn(); _listview.AllColumns.Add(olvColumnId); _listview.AllColumns.Add(olvColumnSent); _listview.AllColumns.Add(olvColumnRec); _listview.AllColumns.Add(olvColumnState); _listview.AllColumns.Add(olvColumnIp); _listview.AllColumns.Add(olvColumnAddress); _listview.CellEditUseWholeCell = false; _listview.Columns.AddRange(new ColumnHeader[] { olvColumnId, olvColumnSent, olvColumnRec, olvColumnState, olvColumnIp, olvColumnAddress }); _listview.Cursor = Cursors.Default; _listview.Dock = DockStyle.Fill; _listview.HideSelection = false; _listview.Location = new Point(0, 0); _listview.Name = "fastObjectListView1"; _listview.ShowGroups = false; _listview.Size = new Size(925, 551); _listview.TabIndex = 21; _listview.UseCompatibleStateImageBehavior = false; _listview.View = View.Details; _listview.VirtualMode = true; // // olvColumnId // olvColumnId.AspectName = "UniqueId"; olvColumnId.Text = "UniqueId"; // // olvColumnSent // olvColumnSent.AspectName = "ParcelsSent"; olvColumnSent.Text = "Parcels Sent"; // // olvColumnRec // olvColumnRec.AspectName = "ParcelsReceived"; olvColumnRec.Text = "Parcels Received"; // // olvColumnState // olvColumnState.AspectName = "State"; olvColumnState.Text = "State"; olvColumnState.Width = 150; // // olvColumnIp // olvColumnIp.AspectName = "IP"; olvColumnIp.Text = "IP"; olvColumnIp.Width = 90; // // olvColumnAddress // olvColumnAddress.AspectName = "Address"; olvColumnAddress.Text = "Hostname"; olvColumnAddress.Width = 125; _listview.Dock = DockStyle.Fill; splitContainer1.Panel1.Controls.Add(_listview); _pierceClient = new PierceClient(); _strumpServer = new StrumpServer(); _strumpServer.Certificate = null; _strumpServer.InitialBufferSize = 2; _strumpServer.Port = 1080; _strumpServer.Stats = new Stats(); _strumpServer.UseSSL = false; _listview.SetObjects(new List <SOCKSRequest>()); Logger.Instance.LogAdded += (sender, log) => { if ((checkBoxLogging.Checked && log.Severity == Severity.Debug) || log.Severity != Severity.Debug) { Print(log.ToString()); } }; _strumpServer.SockOutgoing = parcel => { //if (parcel.Parcel != null && (checkBoxLogging.Checked && parcel.Parcel.Length > 5000)) // Logger.Log("STRUMP REC: " + parcel, Severity.Debug); var pierceMessage = new PierceMessage(parcel); while (!_pierceClient.Connected) { Thread.Sleep(1000); } _pierceClient.Send(pierceMessage); }; _strumpServer.ConnectionAdded += (sender, request) => { _listview.AddObject(request); }; _strumpServer.ConnectionRemoved += (sender, request) => { _listview.RemoveObject(request); }; }