Simple implementation of DataGridView.
Inheritance: Control
Exemplo n.º 1
0
        public void Copy2Paste3Cell()
        {
            DataTable table = CreateTableForCopyPaste();

            Assert.AreEqual(0, table.Rows[0].ItemArray[1]);
            Assert.AreEqual(1, table.Rows[1].ItemArray[1]);
            Assert.AreEqual(2, table.Rows[2].ItemArray[1]);
            Assert.AreEqual(3, table.Rows[3].ItemArray[1]);
            Assert.AreEqual(4, table.Rows[4].ItemArray[1]);

            var tableView = new TableView { Data = table };
            Action<Form> onShown = delegate
            {
                tableView.Focus();
                SendKeys.SendWait("{RIGHT}"); // goto row 1 column 2
                SendKeys.SendWait("+{DOWN}"); // also select cell below
                SendKeys.SendWait("^c"); // copy cells
                SendKeys.SendWait("{DOWN}"); // navigate to cell below
                SendKeys.SendWait("+{DOWN}+{DOWN}"); // also select 2 cells below
                SendKeys.SendWait("^v"); // paste
                Assert.AreEqual(0, table.Rows[0].ItemArray[1]);
                Assert.AreEqual(1, table.Rows[1].ItemArray[1]);
                Assert.AreEqual(0, table.Rows[2].ItemArray[1]); // paste 0 1 to 2 3 4 expects pattern 0 1 0
                Assert.AreEqual(1, table.Rows[3].ItemArray[1]);
                Assert.AreEqual(0, table.Rows[4].ItemArray[1]);
            };

            WindowsFormsTestHelper.ShowModal(tableView, onShown);
        }
Exemplo n.º 2
0
        public void PasteTextIntoFunctionBindingList()
        {
            IFunction function = new Function();
            var argument = new Variable<string>("A");
            function.Arguments.Add(argument);
            var component = new Variable<string>("B");
            function.Components.Add(component);

            var view = new TableView();
            IBindingList bindingList = new FunctionBindingList(function) { SynchronizeInvoke = view };
            view.Data = bindingList;

            const string argumentvalue1 = "argumentvalue1";
            const string componentvalue1 = "componentvalue1";
            const string argumentvalue2 = "argumentvalue2";
            string componentvalue2 = "componentvalue2" + (char)0x03A9;


            Clipboard.SetText(string.Format("{0}\t{1}" + Environment.NewLine +
                                            "{2}\t{3}", argumentvalue1, componentvalue1, argumentvalue2,
                                            componentvalue2));

            //action! pasting the text should fill out the function
            view.PasteClipboardContents();

            Thread.Sleep(2000);

            Assert.AreEqual(argumentvalue1, argument.Values[0]);
            Assert.AreEqual(componentvalue1, component.Values[0]);
            Assert.AreEqual(argumentvalue2, argument.Values[1]);
            Assert.AreEqual(componentvalue2, component.Values[1]);

        }
Exemplo n.º 3
0
        public void ShowReadOnlyTableView()
        {
            var x = new Variable<int>("x");
            var y = new Variable<int>("y");
            y.DefaultValue = -99;

            var f = new Function { Arguments = { x }, Components = { y } };

            f[1] = 1;
            f[5] = 5;
            f[10] = 10;
            f[15] = 15;

            var tableView = new TableView { ReadOnly = true };
            var bindingList = new FunctionBindingList(f) { SynchronizeInvoke = tableView};
            tableView.Data = bindingList;

            WindowsFormsTestHelper.ShowModal(tableView);
        }
 private static TableView GetTableViewWithTwoStringColumnsAndOneRow()
 {
     var tableView = new TableView();
     var tableWithTwoStrings = new DataTable();
     tableWithTwoStrings.Columns.Add("Name", typeof(string));
     tableWithTwoStrings.Columns.Add("B", typeof(string));
     tableWithTwoStrings.Rows.Add("a", "b");
     tableView.Data = tableWithTwoStrings;
     return tableView;
 }
        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 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 PasteFailsIntoNonSquareSelection()
        {
            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 };
            //make a diagonal selection
            tableView.SelectedCells.Add(new TableViewCell(0,0));
            tableView.SelectedCells.Add(new TableViewCell(1, 1));

            var tableViewCopyPasteController = new TableViewPasteController(tableView);
            int callCount = 0;
            tableViewCopyPasteController.PasteFailed += (s, e) => {
                                                                      callCount++;
                                                                      Assert.AreEqual(
                                                                          "Cannot paste into non rectangular selection",
                                                                          e.Value);
            };
            //this should a paste failed event
            tableViewCopyPasteController.PasteLines(new[] { "kees", "anton" });

            Assert.AreEqual(1,callCount);
        }
Exemplo n.º 8
0
 public TableRowCollection(TableView table)
 {
     owner = table;
 }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        public void SortTableViewWhenSettingSortOrder()
        {

            var person = new List<Person>
                             {new Person {Age = 12, Name = "Aaltje"}, 
                              new Person {Age = 11, Name = "Berend"}};
            var tableView = new TableView { Data = person };

            //first sort descending..the first value should be berend
            tableView.Columns[0].SortOrder = SortOrder.Descending;
            Assert.AreEqual("Berend", tableView.GetRowCellValue(0, 0));

            //sort ascending..the first value should be aaltje
            tableView.Columns[0].SortOrder = SortOrder.Ascending;

            Assert.AreEqual("Aaltje", tableView.GetRowCellValue(0, 0));
        }
Exemplo n.º 11
0
 public void AddNewRowToDataSource()
 {
     var persons = new BindingList<Person>();
     var tableView = new TableView { Data = persons };
     tableView.AddNewRowToDataSource();
     Assert.AreEqual(1, persons.Count);
 }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        public void RowCount()
        {
            //empty tableview should have 0 rowcount
            var persons = new BindingList<Person>();
            var tableView = new TableView { Data = persons };
            Assert.AreEqual(0, tableView.RowCount);

            //1 person one row right?
            persons = new BindingList<Person> { new Person { Age = 22, Name = "Jan" } };
            tableView = new TableView { Data = persons };
            Assert.AreEqual(1, tableView.RowCount);
        }
Exemplo n.º 15
0
        public void SetRowCellValueDoesNotWorkOnReadOnlyCell()
        {
            var table = new DataTable();
            table.Columns.Add("readonlycolumn", typeof(string));

            table.Rows.Add(new object[] { "1" });

            var tableView = new TableView { Data = table };

            //read only cell
            tableView.ReadOnlyCellFilter += delegate { return true; };
            

            tableView.SetRowCellValue(0, 0, "2");

            Assert.AreEqual("1", tableView.GetRowCellValue(0, 0));
        }
Exemplo n.º 16
0
        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());
        }
Exemplo n.º 17
0
        public void InsertingValuesinTableAreSortedAutomatically()
        {
            var x = new Variable<int>("x");
            var y = new Variable<int>("y");
            y.DefaultValue = -99;

            var f = new Function { Arguments = { x }, Components = { y } };

            f[1] = 1;
            f[5] = 5;
            f[10] = 10;
            f[15] = 15;

            var tableView = new TableView();
            var bindingList = new FunctionBindingList(f) { SynchronizeInvoke = tableView };
            tableView.Data = bindingList;

            WindowsFormsTestHelper.ShowModal(tableView);
        }
Exemplo n.º 18
0
        public void ShowRowNumbers()
        {
            var person = new List<Person>
                             {new Person {Age = 12, Name = "Aaltje"}, 
                              new Person {Age = 11, Name = "Berend"}};

            for (var i = 0; i < 10; i++)
            {
                person.Add(new Person {Age = 11, Name = "Berend"});
            }

            var tableView = new TableView
                                {
                                    Data = person, ShowRowNumbers = true
                                };

            WindowsFormsTestHelper.ShowModal(tableView);
        }
Exemplo n.º 19
0
            public TableColumnButton(TableView t, TableButtonStyle style)
            {
                BackColor = style.BackColor;
                HoverColor = style.HoverColor;
                BorderColor = style.BorderColor;
                BorderHoverColor = style.BorderHoverColor;
                BorderSelectColor = style.BorderSelectColor;
                Padding = new Padding(8, 0, 8, 0);
                ResizeWidth = 8;
                Size = new Size(t.ColumnsDefaultWidth, 20);
                TextAlign = ContentAlignment.MiddleLeft;

                Owner.UpClick += Owner_UpClick;
            }
Exemplo n.º 20
0
        public void FilterTableOnSettingFilterText()
        {
            var person = new List<Person>
                             {new Person {Age = 12, Name = "Aaltje"}, 
                              new Person {Age = 11, Name = "Berend"}};
            var tableView = new TableView { Data = person };

            //action! set a filter
            tableView.Columns[0].FilterString = "[Name] Like 'Jaap%'";

            //no row should be visible
            Assert.AreEqual(0, tableView.RowCount);
        }
Exemplo n.º 21
0
 public TableColumnCollection(TableView table)
 {
     owner = table;
 }
Exemplo n.º 22
0
        public void IsSorted()
        {
            var person = new List<Person>();
            var tableView = new TableView { Data = person };

            //should be false first
            Assert.IsFalse(tableView.IsSorted);
            //action! set a sort
            tableView.Columns[0].SortOrder = SortOrder.Descending;

            Assert.IsTrue(tableView.IsSorted);
        }
        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());
        }
Exemplo n.º 24
0
        public void ShowTableViewWithListEnumType()
        {
            //demonstrates how easy it is to add custom editor to tableview for bindinglist<T> :)
            //In this case (BindingList<T> you don't need 
            //a typeconverter or comboboxhelper :)
            var tableView = new TableView();
            var list = new BindingList<ClassWithEnum> { new ClassWithEnum { Type = FruitType.Appel } };
            tableView.Data = list;


            var comboBox = new RepositoryItemImageComboBox();
            comboBox.Items.AddEnum(typeof(FruitType));

            tableView.SetColumnEditor(comboBox, 0);
            WindowsFormsTestHelper.ShowModal(tableView);
        }
        public void PasteIntoGridBoundToDataTable()
        {
            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 };

            Clipboard.SetText(string.Format("{0}\t{1}" + Environment.NewLine + "{0}\t{1}", "oe", "oe1"));

            tableView.PasteClipboardContents();

            //WindowsFormsTestHelper.ShowModal(tableView);

            //should overwrite existing row and add another one
            Assert.AreEqual(2, tableWithTwoStrings.Rows.Count);
            Assert.AreEqual("oe", tableWithTwoStrings.Rows[0][0]);
            Assert.AreEqual("oe1", tableWithTwoStrings.Rows[0][1]);
            Assert.AreEqual("oe", tableWithTwoStrings.Rows[1][0]);
            Assert.AreEqual("oe1", tableWithTwoStrings.Rows[1][1]);
        }
Exemplo n.º 26
0
        public void ShowTableViewWithDatatableEnumType()
        {
            //demonstrates how hard it is to add custom editor to tableview for datatable
            //In this case you need 
            //a typeconverter and comboboxhelper :(
            //TODO: look into the differences and abstract away from it
            var dataTable = new DataTable();
            dataTable.Columns.Add("Code", typeof(string));
            dataTable.Columns.Add("SomeEnum", typeof(FruitType));

            for (int i = 0; i < 10; i++)
            {
                dataTable.Rows.Add(new object[] { String.Format("Item{0:000}", i), FruitType.Appel });
            }

            dataTable.AcceptChanges();

            var tableView = new TableView {Data = dataTable};

            var comboBox = new RepositoryItemImageComboBox();
            XtraGridComboBoxHelper.Populate(comboBox, typeof(FruitType));

            tableView.SetColumnEditor(comboBox, 1);
            WindowsFormsTestHelper.ShowModal(tableView);
        }
        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]);
        }
Exemplo n.º 28
0
        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 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());
        }
Exemplo n.º 30
0
        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());
        }