/// <summary> /// Add a row data model to the grid UI, create a corresponding VM. /// The grid row must have cells. /// Use this method when you map your application dataGrid model to this component dataGrid model. /// </summary> /// <param name="gridRow"></param> /// <returns></returns> public IGridRowVM AddRow(IGridRow gridRow) { if (gridRow == null) { return(null); } // check the cells (basic check: just the number of cells) if (gridRow.ListCell.Count() != _collColumnGrid.Count) { return(null); } // the row should be present in the dataGrid model if (!_dynDataGrid.ListRow.Contains(gridRow)) { return(null); } // add it to the view: create VM IGridRowVM rowVM = new GridRowVM(gridRow); _collDataRow.Add(rowVM); RaisePropertyChanged("CollDataRow"); return(rowVM); }
/// <summary> /// Delete the row data model, delete also the corresponding View model. /// Update the UI. /// </summary> /// <param name="row"></param> public void DelRow(IGridRowVM row) { // get the next item in the datagrid, if exists IGridRowVM selectedRowVM = _selectedRow; // remove the VM GridRowVM rowVM = selectedRowVM as GridRowVM; _collDataRow.Remove(selectedRowVM); // remove the row from the datagrid _dynDataGrid.RemoveRow(rowVM.GridRow); RaisePropertyChanged("CollDataRow"); // get the next one or the last, if exists _selectedRow = GetNextOrLast(selectedRowVM); RaisePropertyChanged("SelectedRow"); }
/// <summary> /// Initialization, create the all VM: cols and rows (and cells), corresponding to the dataGrid model. /// </summary> private void Init() { //----build the columns of the dataGrid _collColumnGrid.Clear(); // add list of column definition foreach (IGridColumn column in _dynDataGrid.ListColumn) { AddColumnVM(column); } RaisePropertyChanged("CollColumnGrid"); //----build the rows of the dataGrid _collDataRow.Clear(); foreach (IGridRow gridRow in _dynDataGrid.ListRow) { IGridRowVM rowVM = new GridRowVM(gridRow); _collDataRow.Add(rowVM); } RaisePropertyChanged("CollDataRow"); }
/// <summary> /// Create a row with (empty) cells, at the end. /// create row and cells models and ViewModel. /// Use this method for a basic usage: you use the component dataGrid as your application dataGrid model. /// </summary> /// <returns></returns> public IGridRow CreateRowWithCells() { IGridRow row = new GridRow(_dynDataGrid); // get columns foreach (IGridColumn col in _dynDataGrid.ListColumn) { // create the cell, matching the type defined in the column IGridCell cell = _gridFactory.CreateCell(_dynDataGrid, col, row); row.AddCell(cell); } // add the row to the dataGrid _dynDataGrid.AddRow(row); // add it to the view: create VM IGridRowVM rowVM = new GridRowVM(row); _collDataRow.Add(rowVM); RaisePropertyChanged("CollDataRow"); return(row); }