public static void DefaultColumnFiller(ListView.ColumnHeaderCollection c) { c.Add("ID"); c.Add("Time").Width = -2; c.Add("Type").Width = -2; c.Add("Data").Width = -2; }
public void ColumnHeaderCollection_RemoveAt_HasHandle_Success() { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); var header = new ColumnHeader(); collection.Add(header); collection.Add(new ColumnHeader()); collection.Add(new ColumnHeader()); collection.Add(new ColumnHeader()); Assert.NotEqual(IntPtr.Zero, listView.Handle); // Remove from start. collection.RemoveAt(0); Assert.Equal(3, collection.Count); Assert.Equal(0, collection[0].DisplayIndex); Assert.Equal(1, collection[1].DisplayIndex); Assert.Equal(2, collection[2].DisplayIndex); // Remove from middle. collection.RemoveAt(1); Assert.Equal(2, collection.Count); Assert.Equal(0, collection[0].DisplayIndex); Assert.Equal(1, collection[1].DisplayIndex); // Remove from end. collection.RemoveAt(1); Assert.Single(collection); Assert.Equal(0, collection[0].DisplayIndex); // Remove only. collection.RemoveAt(0); Assert.Empty(collection); Assert.Null(header.ListView); }
public void ColumnHeaderCollection_Add_InvalidTextAlign_ThrowsInvalidEnumArgumentException(HorizontalAlignment textAlign) { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); Assert.Throws <InvalidEnumArgumentException>("value", () => collection.Add("text", 1, textAlign)); Assert.Throws <InvalidEnumArgumentException>("value", () => collection.Add("name", "text", 1, textAlign, "imageKey")); Assert.Throws <InvalidEnumArgumentException>("value", () => collection.Add("name", "text", 1, textAlign, 1)); }
public void ColumnHeaderCollection_Add_ExistsInSameCollection_ThrowsArgumentException() { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); var header = new ColumnHeader(); collection.Add(header); Assert.Throws <ArgumentException>("ch", () => collection.Add(header)); }
public void ColumnHeaderCollection_ContainsKey_Invoke_ReturnsExpected(string key, bool expected) { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); var header1 = new ColumnHeader(); var header2 = new ColumnHeader(); header2.Name = "text"; collection.Add(header1); collection.Add(header2); Assert.Equal(expected, collection.ContainsKey(key)); }
public void ColumnHeaderCollection_Item_GetString_ReturnsExpected(string key, int expectedIndex) { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); var header1 = new ColumnHeader(); var header2 = new ColumnHeader(); header2.Name = "text"; collection.Add(header1); collection.Add(header2); Assert.Equal(expectedIndex != -1 ? collection[expectedIndex] : null, collection[key]); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { ObjectListView instance = null; if (context != null) { instance = context.Instance as ObjectListView; } if (instance == null) { Debug.WriteLine("context.Instance was NOT an ObjectListView"); ListView.ColumnHeaderCollection headers = (ListView.ColumnHeaderCollection)value; if (headers.Count == 0) { headers.Add(new OLVColumn()); instance = (ObjectListView)headers[0].ListView; headers.Clear(); instance.AllColumns.Clear(); } else { instance = (ObjectListView)headers[0].ListView; } } base.EditValue(context, provider, instance.AllColumns); List <OLVColumn> filteredColumns = instance.GetFilteredColumns(View.Details); instance.Columns.Clear(); instance.Columns.AddRange(filteredColumns.ToArray()); return(instance.Columns); }
public void ColumnHeaderCollection_Remove_ColumnHeader_Success() { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); var header = new ColumnHeader(); collection.Add(header); // Remove null. collection.Remove(null); Assert.Same(header, Assert.Single(collection)); collection.Remove(header); Assert.Empty(collection); Assert.Null(header.ListView); Assert.Equal(-1, header.Index); Assert.Equal(-1, header.DisplayIndex); // Remove again. collection.Remove(header); Assert.Empty(collection); Assert.Null(header.ListView); Assert.Equal(-1, header.Index); Assert.Equal(-1, header.DisplayIndex); }
public void ColumnHeaderCollection_Add_NullItem_ThrowsArgumentNullException() { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); Assert.Throws <ArgumentNullException>("ch", () => collection.Add((ColumnHeader)null)); }
public void ColumnHeaderCollection_IListAdd_InvalidValue_ThrowsArgumentException(object value) { var listView = new ListView(); IList collection = new ListView.ColumnHeaderCollection(listView); Assert.Throws <ArgumentException>("value", () => collection.Add(value)); }
public void ColumnHeaderCollection_Clear_InvokeTileWithHandle_Success() { var listView = new ListView { View = View.Tile }; var collection = new ListView.ColumnHeaderCollection(listView); var header = new ColumnHeader(); collection.Add(header); Assert.NotEqual(IntPtr.Zero, listView.Handle); collection.Clear(); Assert.Empty(collection); Assert.Null(header.ListView); Assert.Equal(-1, header.Index); Assert.Equal(0, header.DisplayIndex); // Clear again. collection.Clear(); Assert.Empty(collection); Assert.Null(header.ListView); Assert.Equal(-1, header.Index); Assert.Equal(0, header.DisplayIndex); }
public void ColumnHeaderCollection_IListItem_Set_ThrowsNotSupportedException(int index) { var listView = new ListView(); IList collection = new ListView.ColumnHeaderCollection(listView); collection.Add(new ColumnHeader()); Assert.Throws <NotSupportedException>(() => collection[index] = new ColumnHeader()); }
public void ColumnHeaderCollection_IListItem_GetInvalidIndex_ThrowsArgumentOutOfRangeException(int index) { var listView = new ListView(); IList collection = new ListView.ColumnHeaderCollection(listView); collection.Add(new ColumnHeader()); Assert.Throws <ArgumentOutOfRangeException>("index", () => collection[index]); }
public void ColumnHeaderCollection_IndexOfKey_Invoke_ReturnsExpected(string key, int expected) { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); var header1 = new ColumnHeader(); var header2 = new ColumnHeader(); header2.Name = "text"; collection.Add(header1); collection.Add(header2); Assert.Equal(expected, collection.IndexOfKey(key)); // Call again to validate caching behaviour. Assert.Equal(expected, collection.IndexOfKey(key)); Assert.Equal(-1, collection.IndexOfKey("noSuchKey")); }
public void ColumnHeaderCollection_RemoveAt_InvalidIndex_ThrowsArgumentOutOfRangeException(int index) { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); collection.Add(new ColumnHeader()); Assert.Throws <ArgumentOutOfRangeException>("index", () => collection.RemoveAt(index)); }
public void ColumnHeaderCollection_IListItem_GetValidIndex_ReturnsExpected() { using var listView = new ListView(); IList collection = new ListView.ColumnHeaderCollection(listView); using var header = new ColumnHeader(); collection.Add(header); Assert.Same(header, collection[0]); }
public void ColumnHeaderCollection_IList_Add_Success() { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); var header = new ColumnHeader(); collection.Add(header); Assert.Same(header, Assert.Single(collection)); Assert.Equal(listView, header.ListView); }
public void ColumnHeaderCollection_Add_String_Success(string text, string expectedText) { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); collection.Add(text); ColumnHeader header = Assert.Single(collection.Cast <ColumnHeader>()); Assert.Same(expectedText, header.Text); Assert.Equal(listView, header.ListView); }
public void ColumnHeaderCollection_IListRemove_InvalidItem_Nop(object value) { var listView = new ListView(); IList collection = new ListView.ColumnHeaderCollection(listView); var header = new ColumnHeader(); collection.Add(header); collection.Remove(value); Assert.Same(header, Assert.Single(collection)); }
public void ColumnHeaderCollection_Add_String_Int_Success(string text, int width) { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); collection.Add(text, width); ColumnHeader header = Assert.Single(collection.Cast <ColumnHeader>()); Assert.Equal(text ?? string.Empty, header.Text); Assert.Equal(width, header.Width); Assert.Equal(listView, header.ListView); }
public void ColumnHeaderCollection_Add_ColumnHeader_Success() { using var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); using var header = new ColumnHeader(); collection.Add(header); Assert.Same(header, Assert.Single(collection)); Assert.Equal(listView, header.ListView); Assert.Equal(0, header.Index); Assert.Equal(0, header.DisplayIndex); }
public void ColumnHeaderCollection_IndexOf_Invoke_ReturnsExpected() { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); var header = new ColumnHeader(); collection.Add(header); Assert.Equal(0, collection.IndexOf(header)); Assert.Equal(-1, collection.IndexOf(new ColumnHeader())); Assert.Equal(-1, collection.IndexOf(null)); }
public void ColumnHeaderCollection_IListInsert_ColumnHeader_Success() { var listView = new ListView(); IList collection = new ListView.ColumnHeaderCollection(listView); var header = new ColumnHeader(); collection.Add(new ColumnHeader()); collection.Insert(1, header); Assert.Equal(2, collection.Count); Assert.Same(header, collection[1]); Assert.Same(listView, header.ListView); }
public void ColumnHeaderCollection_Add_String_String_Success(string name, string text) { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); collection.Add(name, text); ColumnHeader header = Assert.Single(collection.Cast <ColumnHeader>()); Assert.Equal(name ?? string.Empty, header.Name); Assert.Equal(text ?? string.Empty, header.Text); Assert.Equal(listView, header.ListView); }
public void ColumnHeaderCollection_Contains_Invoke_ReturnsExpected() { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); var header = new ColumnHeader(); collection.Add(header); Assert.True(collection.Contains(header)); Assert.False(collection.Contains(new ColumnHeader())); Assert.False(collection.Contains(null)); }
public void ColumnHeaderCollection_Add_String_Int_HorizontalAlignment_Success(string text, int width, HorizontalAlignment textAlign, string expectedText) { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); collection.Add(text, width, textAlign); ColumnHeader header = Assert.Single(collection.Cast <ColumnHeader>()); Assert.Equal(expectedText, header.Text); Assert.Equal(width, header.Width); Assert.Equal(textAlign, header.TextAlign); Assert.Equal(listView, header.ListView); }
public void ColumnHeaderCollection_Add_String_String_Int_Success(string name, string text, int width, string expectedName, string expectedText) { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); collection.Add(name, text, width); ColumnHeader header = Assert.Single(collection.Cast <ColumnHeader>()); Assert.Same(expectedName, header.Name); Assert.Same(expectedText, header.Text); Assert.Equal(width, header.Width); Assert.Equal(listView, header.ListView); }
public void ColumnHeaderCollection_CopyTo_NonEmpty_Success() { var listView = new ListView(); IList collection = new ListView.ColumnHeaderCollection(listView); var header = new ColumnHeader(); collection.Add(header); var array = new object[] { 1, 2, 3 }; collection.CopyTo(array, 1); Assert.Equal(new object[] { 1, header, 3 }, array); }
public void ColumnHeaderCollection_Add_String_String_Int_HorizontalAlignment_String_Success(string name, string text, int width, HorizontalAlignment textAlign, string imageKey) { var listView = new ListView(); var collection = new ListView.ColumnHeaderCollection(listView); collection.Add(name, text, width, textAlign, imageKey); ColumnHeader header = Assert.Single(collection.Cast <ColumnHeader>()); Assert.Equal(name ?? string.Empty, header.Name); Assert.Equal(text ?? string.Empty, header.Text); Assert.Equal(width, header.Width); Assert.Equal(textAlign, header.TextAlign); Assert.Equal(imageKey ?? string.Empty, header.ImageKey); Assert.Equal(listView, header.ListView); }
/// <summary> /// Edit a given value /// </summary> /// <param name="context"></param> /// <param name="provider"></param> /// <param name="value"></param> /// <returns></returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { // Figure out which ObjectListView we are working on. This should be the Instance of the context. ObjectListView olv = null; if (context != null) { olv = context.Instance as ObjectListView; } if (olv == null) { //THINK: Can this ever happen? System.Diagnostics.Debug.WriteLine("context.Instance was NOT an ObjectListView"); // Hack to figure out which ObjectListView we are working on ListView.ColumnHeaderCollection cols = (ListView.ColumnHeaderCollection)value; if (cols.Count == 0) { cols.Add(new OLVColumn()); olv = (ObjectListView)cols[0].ListView; cols.Clear(); olv.AllColumns.Clear(); } else { olv = (ObjectListView)cols[0].ListView; } } // Edit all the columns, not just the ones that are visible base.EditValue(context, provider, olv.AllColumns); // Calculate just the visible columns List <OLVColumn> newColumns = olv.GetFilteredColumns(View.Details); olv.Columns.Clear(); olv.Columns.AddRange(newColumns.ToArray()); return(olv.Columns); }