Ejemplo n.º 1
0
        /// <summary>
        /// See <see cref="IBOColSelectorControl.GetBusinessObjectAtRow"/>
        /// </summary>
        public virtual IBusinessObject GetBusinessObjectAtRow(int rowIndex)
        {
            IDataGridViewRow findRow = GetGridRow(rowIndex);

            if (HasObjectIDColumn(findRow))
            {
                Guid value = GetRowObjectIDValue(findRow);
                if (this.DataSetProvider != null)
                {
                    return(this.DataSetProvider.Find(value));
                }
                if (_boCol != null)
                {
                    var businessObject = this._boCol.Find(value);
                    return(businessObject ?? LoadBusinessObject(value));
                }
            }
            if (_gridBase.DataSource is DataView && this.DataSetProvider != null)
            {
                DataRowView dataRowView = GetDataRowView(rowIndex);
                if (dataRowView == null)
                {
                    return(null);
                }

                var result = GetRowObjectIDValue(dataRowView);
                return(this.DataSetProvider.Find(result));
            }
            return(null);
        }
Ejemplo n.º 2
0
 /// <summary>Removes the row from the collection.</summary>
 /// <param name="dataGridViewRow">The row to remove from the <see cref="IDataGridViewRowCollection"></see>.</param>
 /// <exception cref="T:System.InvalidOperationException">The associated <see cref="IDataGridView"></see> control is performing one of the following actions that temporarily prevents new rows from being added:Selecting all cells in the control.Clearing the selection.-or-This method is being called from a handler for some events-or-dataGridViewRow is the row for new records.-or-The associated <see cref="IDataGridView"></see> control is bound to an <see cref="T:System.ComponentModel.IBindingList"></see> implementation with <see cref="P:System.ComponentModel.IBindingList.AllowRemove"></see> and <see cref="P:System.ComponentModel.IBindingList.SupportsChangeNotification"></see> property values that are not both true. </exception>
 /// <exception cref="T:System.ArgumentException">dataGridViewRow is not contained in this collection.-or-dataGridViewRow is a shared row.</exception>
 /// <exception cref="T:System.ArgumentNullException">dataGridViewRow is null.</exception>
 /// <filterpriority>1</filterpriority>
 public void Remove(IDataGridViewRow dataGridViewRow)
 {
     if (dataGridViewRow == null)
     {
         throw new ArgumentNullException("dataGridViewRow");
     }
     _rows.RemoveAt(dataGridViewRow.Index);
 }
Ejemplo n.º 3
0
 protected static void ClearAllSelectedRows(IDataGridViewRowCollection gridRows)
 {
     for (int i = 0; i < gridRows.Count; i++)
     {
         IDataGridViewRow row = gridRows[i];
         row.Selected = false;
     }
 }
Ejemplo n.º 4
0
            /// <summary>
            /// Returns the index of a specified item in the collection
            /// </summary>
            /// <param name="dataGridViewRow">The DataGridViewRow to locate in the DataGridViewRowCollection</param>
            /// <returns>The index of value if it is a DataGridViewRow found in the DataGridViewRowCollection; otherwise, -1.</returns>
            public int IndexOf(IDataGridViewRow dataGridViewRow)
            {
                if (dataGridViewRow == null)
                {
                    throw new ArgumentNullException("dataGridViewRow");
                }

                DataGridViewRowVWG rowWin = (DataGridViewRowVWG)dataGridViewRow;

                return(_rows.IndexOf(rowWin.DataGridViewRow));
            }
Ejemplo n.º 5
0
        public override void TestGetBusinessObjectRow_NullBO()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col;
            IGridBase gridBase = GetGridBaseWith_4_Rows(out col);
            //-------------Assert Preconditions -------------
            //---------------Execute Test ----------------------
            IDataGridViewRow dataGridViewRow = gridBase.GetBusinessObjectRow(null);

            //---------------Test Result -----------------------
            Assert.IsNull(dataGridViewRow);
        }
Ejemplo n.º 6
0
        // ReSharper disable EmptyGeneralCatchClause
#pragma warning disable 168
        private bool HasObjectIDColumn(IDataGridViewRow findRow)
        {
            try
            {
                var dataGridViewCell = findRow.Cells[IDColumnName];

                return(true);
            }
            catch (Exception)

            {
            }
            return(false);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Sets the select row.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="e">The <see cref="DataGridViewEventArgs" /> instance containing the event data.</param>
        private void SetSelectRow(Control item, DataGridViewEventArgs e)
        {
            try
            {
                ControlHelper.FreezeControl(this, true);
                if (item == null)
                {
                    return;
                }
                if (item.Visible == false)
                {
                    return;
                }
                this.FindForm().ActiveControl = this;
                this.FindForm().ActiveControl = item;
                if (m_selectRow != item)
                {
                    if (m_selectRow != null)
                    {
                        m_selectRow.SetSelect(false);
                    }
                    m_selectRow = item as IDataGridViewRow;
                    m_selectRow.SetSelect(true);

                    if (this.panRow.Controls.Count > 0)
                    {
                        if (item.Location.Y < 0)
                        {
                            this.panRow.AutoScrollPosition = new Point(0, Math.Abs(this.panRow.Controls[this.panRow.Controls.Count - 1].Location.Y) + item.Location.Y);
                        }
                        else if (item.Location.Y + m_rowHeight > this.panRow.Height)
                        {
                            this.panRow.AutoScrollPosition = new Point(0, Math.Abs(this.panRow.AutoScrollPosition.Y) + item.Location.Y - this.panRow.Height + m_rowHeight);
                        }
                    }
                }


                if (ItemClick != null)
                {
                    ItemClick(item, e);
                }
            }
            finally
            {
                ControlHelper.FreezeControl(this, false);
            }
        }
Ejemplo n.º 8
0
        protected override int SelectedIndex(IBOColSelectorControl colSelector)
        {
            IGridBase        gridSelector = (IGridBase)colSelector;
            IDataGridViewRow currentRow   = null;

            if (gridSelector.SelectedRows.Count > 0)
            {
                currentRow = gridSelector.SelectedRows[0];
            }
            if (currentRow == null)
            {
                return(-1);
            }

            return(gridSelector.Rows.IndexOf(currentRow));
        }
Ejemplo n.º 9
0
        protected override int SelectedIndex(IBOColSelectorControl colSelector)
        {
            IEditableGrid    gridSelector = ((IEditableGridControl)colSelector).Grid;
            IDataGridViewRow currentRow   = null;

            if (gridSelector.SelectedRows.Count > 0)
            {
                currentRow = gridSelector.SelectedRows[0];
            }

            if (currentRow == null)
            {
                return(-1);
            }

            return(gridSelector.Rows.IndexOf(currentRow));
        }
Ejemplo n.º 10
0
        public override void TestGetBusinessObjectRow()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col;
            IGridBase gridBase      = GetGridBaseWith_4_Rows(out col);
            MyBO      myBO2         = col[2];
            const int expectedIndex = 2;

            //-------------Assert Preconditions -------------
            Assert.AreSame(myBO2, gridBase.GetBusinessObjectAtRow(expectedIndex));
            //---------------Execute Test ----------------------
            IDataGridViewRow dataGridViewRow = gridBase.GetBusinessObjectRow(myBO2);

            //---------------Test Result -----------------------
            Assert.IsNotNull(dataGridViewRow, "Should return related row");
            Assert.AreEqual(expectedIndex, dataGridViewRow.Index);
        }
Ejemplo n.º 11
0
        public void TestVWG_Set_BusinessObjectCollection()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects();
            IGridBase gridBase = CreateGridBaseStub();

            SetupGridColumnsForMyBo(gridBase);
            const string propName = "TestProp";
            const int    rowIndex = 1;

            //---------------Execute Test ----------------------
            gridBase.BusinessObjectCollection = col;

            //---------------Test Result -----------------------
            MyBO              selectedBo = (MyBO)gridBase.GetBusinessObjectAtRow(rowIndex);
            IDataGridViewRow  row        = gridBase.Rows[rowIndex];
            IDataGridViewCell cell       = row.Cells[propName];

            Assert.AreEqual(selectedBo.TestProp, cell.Value);
        }
Ejemplo n.º 12
0
        public void TestVWG_RowShowingBusinessObjectsValues()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects();
            IGridBase gridBase = CreateGridBaseStub();

            SetupGridColumnsForMyBo(gridBase);
            const string propName = "TestProp";
            const int    rowIndex = 1;

            //---------------Execute Test ----------------------
#pragma warning disable 618,612 //Maintained for backward compatibility testing
            gridBase.SetBusinessObjectCollection(col);
#pragma warning restore 618,612

            //---------------Test Result -----------------------
            MyBO              selectedBo = (MyBO)gridBase.GetBusinessObjectAtRow(rowIndex);
            IDataGridViewRow  row        = gridBase.Rows[rowIndex];
            IDataGridViewCell cell       = row.Cells[propName];
            Assert.AreEqual(selectedBo.TestProp, cell.Value);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 刷新数据
        /// </summary>
        public void ReloadSource()
        {
            if (DesignMode)
            {
                return;
            }
            try
            {
                ControlHelper.FreezeControl(this.panRow, true);
                //this.panRow.Controls.Clear();
                Rows = new List <IDataGridViewRow>();
                if (m_columns == null || m_columns.Count <= 0)
                {
                    return;
                }
                if (m_dataSource != null)
                {
                    int     intIndex = 0;
                    Control lastItem = null;

                    int intSourceCount = 0;
                    if (m_dataSource is DataTable)
                    {
                        intSourceCount = (m_dataSource as DataTable).Rows.Count;
                    }
                    else if (typeof(IList).IsAssignableFrom(m_dataSource.GetType()))
                    {
                        intSourceCount = (m_dataSource as IList).Count;
                    }

                    foreach (Control item in this.panRow.Controls)
                    {
                        if (intIndex >= intSourceCount)
                        {
                            item.Visible = false;
                        }
                        else
                        {
                            var row = (item as IDataGridViewRow);
                            row.IsShowCheckBox = m_isShowCheckBox;
                            if (m_dataSource is DataTable)
                            {
                                row.DataSource = (m_dataSource as DataTable).Rows[intIndex];
                            }
                            else
                            {
                                row.DataSource = (m_dataSource as IList)[intIndex];
                            }
                            row.BindingCellData();
                            if (row.RowHeight != m_rowHeight)
                            {
                                row.RowHeight = m_rowHeight;
                            }
                            item.Visible = true;
                            item.BringToFront();
                            if (lastItem == null)
                            {
                                lastItem = item;
                            }
                            Rows.Add(row);
                        }
                        intIndex++;
                    }

                    if (intIndex < intSourceCount)
                    {
                        for (int i = intIndex; i < intSourceCount; i++)
                        {
                            IDataGridViewRow row = (IDataGridViewRow)Activator.CreateInstance(m_rowType);
                            if (m_dataSource is DataTable)
                            {
                                row.DataSource = (m_dataSource as DataTable).Rows[i];
                            }
                            else
                            {
                                row.DataSource = (m_dataSource as IList)[i];
                            }
                            row.Columns = m_columns;
                            List <Control> lstCells = new List <Control>();
                            row.IsShowCheckBox = m_isShowCheckBox;
                            row.ReloadCells();
                            row.BindingCellData();


                            Control rowControl = (row as Control);
                            this.panRow.Controls.Add(rowControl);
                            row.RowHeight            = m_rowHeight;
                            rowControl.Dock          = DockStyle.Top;
                            row.CellClick           += (a, b) => { SetSelectRow(rowControl, b); };
                            row.CheckBoxChangeEvent += (a, b) => { SetSelectRow(rowControl, b); };
                            row.RowCustomEvent      += (a, b) => { if (RowCustomEvent != null)
                                                                   {
                                                                       RowCustomEvent(a, b);
                                                                   }
                            };
                            row.SourceChanged += RowSourceChanged;
                            rowControl.BringToFront();
                            Rows.Add(row);

                            if (lastItem == null)
                            {
                                lastItem = rowControl;
                            }
                        }
                    }
                    if (lastItem != null && intSourceCount == m_showCount)
                    {
                        lastItem.Height = this.panRow.Height - (m_showCount - 1) * m_rowHeight - 2;
                    }
                }
                else
                {
                    foreach (Control item in this.panRow.Controls)
                    {
                        item.Visible = false;
                    }
                }
            }
            finally
            {
                ControlHelper.FreezeControl(this.panRow, false);
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Gets the Object ID for a given row.
 /// This assumes that the row has a column <see cref="IDColumnName"/>.
 /// </summary>
 /// <param name="row"></param>
 /// <returns></returns>
 public Guid GetRowObjectIDValue(IDataGridViewRow row)
 {
     object idValue = row.Cells[IDColumnName].Value;
     return ConvertToGuid(idValue);
 }
Ejemplo n.º 15
0
        // ReSharper disable EmptyGeneralCatchClause
#pragma warning disable 168
        private bool HasObjectIDColumn(IDataGridViewRow findRow)
        {
            try
            {
                var dataGridViewCell = findRow.Cells[IDColumnName];

                return true;
            }
            catch (Exception)

            {
            }
            return false;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 刷新数据
        /// </summary>
        public void ReloadSource()
        {
            if (DesignMode)
            {
                return;
            }
            try
            {
                ControlHelper.FreezeControl(this, true);
                panHead.Location = new Point(0, 0);
                Rows             = new List <IDataGridViewRow>();
                if (m_columns == null || m_columns.Count <= 0)
                {
                    return;
                }
                if (m_dataSource != null)
                {
                    int intIndex = 0;

                    int intSourceCount = 0;
                    if (m_dataSource is DataTable)
                    {
                        intSourceCount = (m_dataSource as DataTable).Rows.Count;
                    }
                    else if (typeof(IList).IsAssignableFrom(m_dataSource.GetType()))
                    {
                        intSourceCount = (m_dataSource as IList).Count;
                    }

                    foreach (Control item in this.panRow.Controls)
                    {
                        if (intIndex >= intSourceCount)
                        {
                            item.Visible = false;
                        }
                        else
                        {
                            var row = (item as IDataGridViewRow);
                            row.IsShowCheckBox = m_isShowCheckBox;
                            if (m_dataSource is DataTable)
                            {
                                row.DataSource = (m_dataSource as DataTable).Rows[intIndex];
                            }
                            else
                            {
                                row.DataSource = (m_dataSource as IList)[intIndex];
                            }
                            row.BindingCellData();
                            if (row.RowHeight != m_rowHeight)
                            {
                                row.RowHeight = m_rowHeight;
                            }
                            item.Visible = true;
                            item.Width   = panHead.Width;

                            Rows.Add(row);
                            row.RowIndex = Rows.IndexOf(row);
                        }
                        intIndex++;
                    }

                    if (intIndex < intSourceCount)
                    {
                        for (int i = intIndex; i < intSourceCount; i++)
                        {
                            IDataGridViewRow row = (IDataGridViewRow)Activator.CreateInstance(m_rowType);
                            if (m_dataSource is DataTable)
                            {
                                row.DataSource = (m_dataSource as DataTable).Rows[i];
                            }
                            else
                            {
                                row.DataSource = (m_dataSource as IList)[i];
                            }
                            row.Columns = m_columns;
                            List <Control> lstCells = new List <Control>();
                            row.IsShowCheckBox = m_isShowCheckBox;
                            row.ReloadCells();
                            row.BindingCellData();

                            Control rowControl = (row as Control);
                            rowControl.Width         = panHead.Width;
                            row.RowHeight            = m_rowHeight;
                            row.CellClick           += (a, b) => { this.FindForm().ActiveControl = this; rowControl.Focus(); SetSelectRow(rowControl, b); };
                            row.CheckBoxChangeEvent += (a, b) => { SetSelectRow(rowControl, b); };
                            row.RowCustomEvent      += (a, b) => { if (RowCustomEvent != null)
                                                                   {
                                                                       RowCustomEvent(a, b);
                                                                   }
                            };
                            row.SourceChanged += RowSourceChanged;
                            Rows.Add(row);
                            row.RowIndex = Rows.IndexOf(row);
                            this.panRow.Controls.Add(rowControl);
                        }
                    }

                    //this.panRow.Height = intSourceCount * RowHeight;
                }
                else
                {
                    foreach (Control item in this.panRow.Controls)
                    {
                        item.Visible = false;
                    }
                }
            }
            finally
            {
                ControlHelper.FreezeControl(this, false);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets the Object ID for a given row.
        /// This assumes that the row has a column <see cref="IDColumnName"/>.
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public Guid GetRowObjectIDValue(IDataGridViewRow row)
        {
            object idValue = row.Cells[IDColumnName].Value;

            return(ConvertToGuid(idValue));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 移除行
        /// </summary>
        /// <param name="rowIndex"></param>
        public void EditRow(int rowIndex)
        {
            if (DesignMode)
            {
                return;
            }
            try
            {
                this.panRow.Controls.Clear();
                var NewRows = new List <IDataGridViewRow>();
                if (m_columns == null || m_columns.Count <= 0)
                {
                    return;
                }
                if (this.Rows != null)
                {
                    int     index          = 0;
                    Control lastItem       = null;
                    int     intSourceCount = 0;
                    intSourceCount = this.Rows.Count;

                    for (int i = 0; i < intSourceCount; i++)
                    {
                        IDataGridViewRow row = (IDataGridViewRow)Activator.CreateInstance(m_rowType);
                        row.DataSource = this.Rows[i].DataSource;
                        row.Columns    = m_columns;
                        row.RowIndex   = index;
                        List <Control> lstCells = new List <Control>();
                        row.IsShowCheckBox = m_isShowCheckBox;
                        if (i == rowIndex)
                        {
                            row.AddCells();
                            row.BindingAddCellData();
                        }
                        else
                        {
                            row.ReloadCells();
                            row.BindingCellData();
                        }

                        Control rowControl = (row as Control);
                        this.panRow.Controls.Add(rowControl);
                        row.RowHeight            = m_rowHeight;
                        rowControl.Dock          = DockStyle.Top;
                        row.CellClick           += (a, b) => { SetSelectRow(rowControl, b); };
                        row.CheckBoxChangeEvent += (a, b) => { SetSelectRow(rowControl, b); };
                        row.RowCustomEvent      += (a, b) => { if (RowCustomEvent != null)
                                                               {
                                                                   RowCustomEvent(a, b);
                                                               }
                        };
                        row.SourceChanged += RowSourceChanged;
                        rowControl.BringToFront();
                        NewRows.Add(row);
                        ++index;

                        if (lastItem == null)
                        {
                            lastItem = rowControl;
                        }
                    }

                    if (lastItem != null && intSourceCount == m_showCount)
                    {
                        lastItem.Height = this.panRow.Height - (m_showCount - 1) * m_rowHeight;
                    }
                }
                else
                {
                    foreach (Control item in this.panRow.Controls)
                    {
                        item.Visible = false;
                    }
                }
                Rows.Clear();
                Rows.AddRange(NewRows);
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 刷新数据
        /// </summary>
        public void AddRow(object rowData)
        {
            if (DesignMode)
            {
                return;
            }
            try
            {
                this.panRow.Controls.Clear();
                Rows = new List <IDataGridViewRow>();
                if (m_columns == null || m_columns.Count <= 0)
                {
                    return;
                }
                if (m_dataSource != null)
                {
                    int index = 0;

                    #region 新增的行
                    if (m_dataSource != null)
                    {
                        IDataGridViewRow row = (IDataGridViewRow)Activator.CreateInstance(m_rowType);
                        if (m_dataSource is DataTable)
                        {
                            row.DataSource = (m_dataSource as DataTable).NewRow();
                        }
                        else if (typeof(IList).IsAssignableFrom(m_dataSource.GetType()))
                        {
                            var type         = (m_dataSource as IList)[0].GetType();
                            var model        = Activator.CreateInstance(type);
                            var type1        = rowData.GetType();
                            var props        = type.GetProperties();
                            var rowDataProps = type1.GetProperties();
                            foreach (var prop in props)
                            {
                                if (prop.CanWrite)
                                {
                                    foreach (var rowDataProp in rowDataProps)
                                    {
                                        try
                                        {
                                            if (prop.Name == rowDataProp.Name)
                                            {
                                                var data = rowDataProp.GetValue(rowData, null);
                                                if (data != DBNull.Value)
                                                {
                                                    prop.SetValue(model, Convert.ChangeType(data, prop.PropertyType), null);
                                                }
                                            }
                                        }
                                        catch (IndexOutOfRangeException)
                                        {
                                            continue;
                                        }
                                    }
                                }
                            }
                            row.DataSource = model;
                        }
                        row.RowIndex       = index;
                        row.Columns        = m_columns;
                        row.IsShowCheckBox = m_isShowCheckBox;
                        row.AddCells();
                        row.BindingAddCellData();

                        Control addRowControl = (row as Control);
                        this.panRow.Controls.Add(addRowControl);
                        row.RowHeight            = m_rowHeight;
                        addRowControl.Dock       = DockStyle.Top;
                        row.CellClick           += (a, b) => { SetSelectRow(addRowControl, b); };
                        row.CheckBoxChangeEvent += (a, b) => { SetSelectRow(addRowControl, b); };
                        row.RowCustomEvent      += (a, b) => { if (RowCustomEvent != null)
                                                               {
                                                                   RowCustomEvent(a, b);
                                                               }
                        };
                        row.SourceChanged += RowSourceChanged;
                        addRowControl.BringToFront();
                        Rows.Add(row);
                        ++index;
                    }
                    #endregion

                    #region 旧的数据源
                    Control lastItem       = null;
                    int     intSourceCount = 0;
                    if (m_dataSource is DataTable)
                    {
                        intSourceCount = (m_dataSource as DataTable).Rows.Count;
                    }
                    else if (typeof(IList).IsAssignableFrom(m_dataSource.GetType()))
                    {
                        intSourceCount = (m_dataSource as IList).Count;
                    }

                    for (int i = 0; i < intSourceCount; i++)
                    {
                        IDataGridViewRow row = (IDataGridViewRow)Activator.CreateInstance(m_rowType);
                        if (m_dataSource is DataTable)
                        {
                            row.DataSource = (m_dataSource as DataTable).Rows[i];
                        }
                        else
                        {
                            row.DataSource = (m_dataSource as IList)[i];
                        }
                        row.Columns        = m_columns;
                        row.RowIndex       = index;
                        row.IsShowCheckBox = m_isShowCheckBox;
                        row.ReloadCells();
                        row.BindingCellData();


                        Control rowControl = (row as Control);
                        this.panRow.Controls.Add(rowControl);
                        row.RowHeight            = m_rowHeight;
                        rowControl.Dock          = DockStyle.Top;
                        row.CellClick           += (a, b) => { SetSelectRow(rowControl, b); };
                        row.CheckBoxChangeEvent += (a, b) => { SetSelectRow(rowControl, b); };
                        row.RowCustomEvent      += (a, b) => { if (RowCustomEvent != null)
                                                               {
                                                                   RowCustomEvent(a, b);
                                                               }
                        };
                        row.SourceChanged += RowSourceChanged;
                        rowControl.BringToFront();
                        Rows.Add(row);
                        ++index;

                        if (lastItem == null)
                        {
                            lastItem = rowControl;
                        }
                    }

                    if (lastItem != null && intSourceCount == m_showCount)
                    {
                        lastItem.Height = this.panRow.Height - (m_showCount - 1) * m_rowHeight;
                    }
                    #endregion
                }
                else
                {
                    foreach (Control item in this.panRow.Controls)
                    {
                        item.Visible = false;
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }