public override void fillMe() { DataGridView _dg = (DataGridView)targetControl; _dg.Rows.Clear(); //тут надо что то отключить, чтобы он не выводил событие SelectionChanged при заливке //fillViewControlFlag = true; //заливаем контрол //запускаем итерацию по датасорсу формы //object val; DataGridViewRow dgr; ObjectParameters.ObjectParameter val = null; DataGridViewCell newCell = null; foreach (IKeepable t in data.dataSource.items) { dgr = new DataGridViewRow(); //первый столбец - чекбоксы для мультиселекта newCell = new DataGridViewCheckBoxCell(); newCell.Value = false; newCell.ReadOnly = false; dgr.Cells.Add(newCell); dgr = readDataGridViewRow(t, _dg, dgr); _dg.Rows.Add(dgr); } }
private DataGridViewRow readDataGridViewRow(IKeepable t, DataGridView _dg, DataGridViewRow dgr, bool reRead = false, string colorCode = "") { //читает row из объекта //теперь поехали перебирать колонки DataGridViewCell workingCell = null; ObjectParameters.ObjectParameter val = null; string stringValue = ""; bool readOnlyCell; Lib.FieldInfo f = null; DateTime dateTime; bool itsNull; for (int i = 0; i < data.dataColumns.Count; i++) { f = t.fieldsInfo.getFieldInfoObjectByFieldClassName(data.dataColumns[i].srcDataFieldName); if (f == null) { return(dgr); } itsNull = f.isNull; val = ObjectParameters.getObjectParameterByName(t, data.dataColumns[i].srcDataFieldName); switch (f.fieldType) { case Lib.FieldTypeEnum.Date: dateTime = Convert.ToDateTime(val.value); stringValue = (itsNull) ? "" : dateTime.ToString("dd.MM.yyyy"); break; case Lib.FieldTypeEnum.Time: dateTime = Convert.ToDateTime(val.value); stringValue = (itsNull) ? "" : dateTime.ToString("hh:mm:ss"); break; case Lib.FieldTypeEnum.DateTime: dateTime = Convert.ToDateTime(val.value); stringValue = (itsNull) ? "" : dateTime.ToString("dd.MM.yyyy hh:mm:ss"); break; case Lib.FieldTypeEnum.Int: case Lib.FieldTypeEnum.Double: stringValue = (itsNull) ? "" : fn.toStringNullConvertion(val.value); break; case Lib.FieldTypeEnum.String: case Lib.FieldTypeEnum.Memo: stringValue = (itsNull) ? "" : fn.toStringNullConvertion(val.value); break; default: stringValue = fn.toStringNullConvertion(val.value); break; } workingCell = reRead ? dgr.Cells[i + 1] : new DataGridViewTextBoxCell(); readOnlyCell = true; // (editabilityMode== DataGridEditabilityMode.NotEditableAtAll) ? false : switch (_dg.Columns[i + 1].CellType.Name) { case "DataGridViewTextBoxCell": workingCell.Value = (val == null) ? "" : (val.value == null ? "" : stringValue); break; case "DataGridViewCheckBoxCell": workingCell.Value = (val == null) ? false : (bool)val.value; //fn.dp("newCell.Value=" + newCell.Value.ToString()); break; //TODO здесь другие типы контролов } if (!reRead) { dgr.Cells.Add(workingCell); } workingCell.ReadOnly = readOnlyCell; } //раскраска //если пустая строка, убрать раскраску if (colorCode == "") { dgr.DefaultCellStyle.BackColor = Color.White; } if (paint != null) { Color c = paint.getMyColor(t); // fn.dp("COLOR=" + c.ToString()); //if (c==Color.White) fn.dp () dgr.DefaultCellStyle.BackColor = paint.getMyColor(t); } return(dgr); }