public override object Clone()
        {
            DataGridViewTextAndImageColumn c = base.Clone() as DataGridViewTextAndImageColumn;

            c._imageValue = this._imageValue;
            c._imageSize  = this._imageSize;
            c._imageAlign = this._imageAlign;

            return(c);
        }
예제 #2
0
        private void RenderGrid()
        {
            if (!this.DesignMode && this.DataSource != null)
            {
                this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
                this.ColumnHeadersHeight         = MIN_HEADER_HEIGHT;

                // Add Employee Columns
                var employeeIdColumn = new DataGridViewTextAndImageColumn()
                {
                    Name       = "EmployeeId",
                    HeaderText = "Id",
                    Frozen     = true,
                    ImageAlign = ContentAlignment.MiddleLeft,
                };
                this.Columns.Add(employeeIdColumn);

                var employeeFullNameColumn = new DataGridViewTextBoxColumn()
                {
                    Name       = "EmployeeFullName",
                    HeaderText = "Full Name",
                    Frozen     = true,
                };
                this.Columns.Add(employeeFullNameColumn);

                // Add column date
                for (int i = 0; i < this.DayCount; i++)
                {
                    var idDate = _fromDate.AddDays(i);
                    DataGridViewTimeSheetColumn tsColumn = new DataGridViewTimeSheetColumn(idDate)
                    {
                        HeaderText = idDate.ToString(this.HeaderDateFormat),
                    };
                    this.Columns.Add(tsColumn);
                }

                var Data = this.DataSource as IList <TimeSheetItem>;
                if (Data != null)
                {
                    if (Data != null && Data.Count > 0)
                    {
                        for (int i = 0; i < Data.Count; i++)
                        {
                            var tsItem = Data[i];
                            if (tsItem.TimeSheetDays != null && tsItem.TimeSheetDays.Count > 0)
                            {
                                var dtgRow = this.Rows[i];

                                // Bind employee info into header column
                                dtgRow.Cells[EMPLOYEE_ID_COLUMN_NAME].Value       = tsItem.EmployeeId;
                                dtgRow.Cells[EMPLOYEE_FULLNAME_COLUMN_NAME].Value = tsItem.EmployeeFullName;

                                // Bind timesheet days
                                for (int j = 0; j < tsItem.TimeSheetDays.Count; j++)
                                {
                                    var tsDay = tsItem.TimeSheetDays[j];

                                    // old method: bind by array
                                    //int columnDayIndex = (tsDay.Day - this.FromDate).Days + this.ColumnHeaderCount;
                                    //this.Rows[i].Cells[columnDayIndex].Value = tsDay;

                                    // new method: bind by column name
                                    var columnDayName = tsDay.Day.ToString(COLUMN_TIMESHEET_NAME_ID_FORMAT);
                                    var cell          = this.Rows[i].Cells[columnDayName];
                                    if (cell != null)
                                    {
                                        cell.Value = tsDay;
                                    }
                                }
                            } // Check TimeSheetDay is available
                        }     // Bind data row
                    }         // Check Data is available
                }
            }
        }