public void PasteFillsSelection() { var list = new BindingList<Person>() { new Person {Name = "jan", Age = 25}, new Person {Name = "fon", Age = 33}, new Person {Name = "peer", Age = 25}, new Person {Name = "fo", Age = 33} }; var tableView = new TableView {Data = list}; //select all cells in first column tableView.SelectCells(0, 0, 3, 0); //hook up a copy paste controller var tableViewCopyPasteController = new TableViewPasteController(tableView); //this should set the first column to kees,anton,kees,anton tableViewCopyPasteController.PasteLines(new[] {"kees", "anton"}); //asert the names are now like this Assert.AreEqual(new[] {"kees", "anton", "kees", "anton"}, list.Select(p => p.Name).ToArray()); }
public void PastingIntoReadOnlyCellsDoesNotChangeTheValues() { var tableWithTwoStrings = new DataTable(); tableWithTwoStrings.Columns.Add("A", typeof(string)); tableWithTwoStrings.Columns.Add("B", typeof(string)); tableWithTwoStrings.Rows.Add("a", "b"); var tableView = new TableView { Data = tableWithTwoStrings }; //values in the first column are read only tableView.ReadOnlyCellFilter = delegate (TableViewCell cell) { return cell.ColumnIndex== 0; }; //select top row tableView.SelectCells(0, 0, 0, 1); var tableViewCopyPasteController = new TableViewPasteController(tableView); //paste some non sense. tableViewCopyPasteController.PasteLines(new[] { "c\td" }); //only column b should have changed Assert.AreEqual("a", tableWithTwoStrings.Rows[0][0]); Assert.AreEqual("d", tableWithTwoStrings.Rows[0][1]); }
public void PasteIntoARowSelection() { var tableWithTwoStrings = new DataTable(); tableWithTwoStrings.Columns.Add("A", typeof(string)); tableWithTwoStrings.Columns.Add("B", typeof(string)); tableWithTwoStrings.Rows.Add("a", "b"); var tableView = new TableView { Data = tableWithTwoStrings }; var tableViewCopyPasteController = new TableViewPasteController(tableView); //select top row tableView.SelectCells(0, 0, 0, 1); //paste some non sense. tableViewCopyPasteController.PasteLines(new[] { "c" }); //first line should now be [c c] Assert.AreEqual("c", tableWithTwoStrings.Rows[0][0]); Assert.AreEqual("c", tableWithTwoStrings.Rows[0][1]); }
public void CopyPasteEnumInBindingList() { var list = new BindingList<ClassWithEnum> { new ClassWithEnum{Type = FruitType.Banaan}, new ClassWithEnum{Type = FruitType.Peer} }; var tableView = new TableView { Data = list }; tableView.SetEnumComboboxEditor(typeof(FruitType),0); var tableViewCopyPasteController = new TableViewPasteController(tableView); //select 2nd row tableView.SelectCells(1,0,1,0); //paste twee bananen en een peer ;) tableViewCopyPasteController.PasteLines(new[]{"Banaan","Banaan","Peer" }); //we should have 3 bananas and a pear Assert.AreEqual("Banaan","Banaan","Banaan","Peer",list.Select(c=>c.Type).ToArray()); }
public void PasteTakesInvisibleColumnsIntoAccount() { //if a possible paste is too big it is important to not exceed the visiblecolcount - 1 var list = new BindingList<Person>() { new Person {Name = "jan", Age = 25}, new Person {Name = "fon", Age = 33}, new Person {Name = "peer", Age = 25}, new Person {Name = "fo", Age = 33} }; var tableView = new TableView {Data = list}; //hide the age column tableView.Columns[1].Visible = false; //select top left tableView.SelectCells(0, 0, 0, 0); var tableViewCopyPasteController = new TableViewPasteController(tableView); //paste some non sense tableViewCopyPasteController.PasteLines(new[] {"kees\tkan\twel"}); //first person should be kees now Assert.AreEqual("kees", list[0].Name); }
public void DeleteSelectionTakesAllowDeleteRowsIntoAccount() { var persons = new List<Person> {new Person {Name = "Aaltje",Age = 12 }, new Person {Name = "Berend",Age = 11 }}; var tableView = new TableView { Data = persons }; //select the top row tableView.SelectCells(0, 0, 0, 1); //action! delete the row tableView.AllowDeleteRow = false; tableView.DeleteCurrentSelection(); //assert aaltje got 'reset' Assert.AreEqual(new[] {"", "Berend" }, persons.Select(p => p.Name).ToArray()); Assert.AreEqual(new[] { 0, 11 }, persons.Select(p => p.Age).ToArray()); }
public void DeleteSelectionOnReadOnlyColumnDoesNothing() { var persons = new List<Person> {new Person {Name = "Aaltje",Age = 12 }, new Person {Name = "Berend",Age = 11 }}; var tableView = new TableView { Data = persons }; //select the top row tableView.SelectCells(0, 1, 0, 1); tableView.Columns[1].ReadOnly = true; //action! try to delete something tableView.DeleteCurrentSelection(); //assert all is well Assert.AreEqual(12, persons[0].Age); Assert.AreEqual(2, persons.Count); }
public void DeleteSelectionRemovesRowIfAllCellsInARowAreSelected() { var persons = new List<Person> {new Person {Name = "Aaltje",Age = 12}, new Person {Name = "Berend",Age = 11 }}; var tableView = new TableView { Data = persons }; //select the top row tableView.SelectCells(0, 0, 0, 1); //action! delete the row tableView.DeleteCurrentSelection(); //assert we only have berend now Assert.AreEqual(new[] { "Berend" }, persons.Select(p => p.Name).ToArray()); }
public void DeleteSelectionRemovesValueIfCellWasSelect() { var persons = new List<Person> {new Person {Name = "Aaltje",Age = 12 }, new Person {Name = "Berend",Age = 11 }}; var tableView = new TableView { Data = persons }; //select the twelve tableView.SelectCells(0, 1, 0, 1); //action! delete the row tableView.DeleteCurrentSelection(); //assert we 'deleted' the age Assert.AreEqual(0,persons[0].Age); }
public void ChangeSelection() { //empty tableview should have 0 rowcount var persons = new BindingList<Person>(); for (int i = 0; i < 10; i++) { persons.Add(new Person()); } var tableView = new TableView { Data = persons }; var selectionChangedcount = 0; var selectedRowChanged = 0; tableView.SelectedRowChanged += delegate { selectedRowChanged++; }; tableView.SelectionChanged += delegate { selectionChangedcount++; }; //select cells tableView.SelectCells(5, 0, 9, 1); Assert.AreEqual(10, selectionChangedcount); var currentOld = tableView.CurrentRowObject; tableView.SelectedDisplayRowIndex = 1; var currentnew = tableView.CurrentRowObject; Assert.AreEqual(1, selectedRowChanged); Assert.AreNotEqual(currentOld, currentnew); }
public void SelectCells() { //empty tableview should have 0 rowcount var persons = new BindingList<Person>(); for (int i = 0; i < 10; i++) { persons.Add(new Person()); } var tableView = new TableView { Data = persons }; //select cells tableView.SelectCells(5, 0, 9, 1); //check the bottom cells are all selected Assert.AreEqual(10, tableView.SelectedCells.Count); }
public void CopySelectionIntoClipBoard() { var table = new DataTable(); table.Columns.Add("column1", typeof(string)); table.Columns.Add("column2", typeof(string)); table.Rows.Add(new object[] { "1", "2" }); table.Rows.Add(new object[] { "3", "4" }); var tableView = new TableView { Data = table }; //select two rows tableView.SelectCells(0, 0, 1, 1); //action! copy selection to clipboard //tableView.CopySelection tableView.CopySelectionToClipboard(); Assert.AreEqual("1\t2\r\n3\t4\r\n", Clipboard.GetText()); }