public void GetData(IBedValueWriter writer) { if (m_row == null) { return; } m_row.ReadValue(m_colindex); writer.ReadFrom(m_row); }
private void MyPaintCell(DataGridViewCellPaintingEventArgs e) { var style = m_settings._Style; if (m_lookupBrush.Color != style.LookupHintColor) { m_lookupBrush.Dispose(); m_lookupBrush = new SolidBrush(style.LookupHintColor); } BedRow row = GetRow(e.RowIndex); row.ReadValue(e.ColumnIndex); var type = row.GetFieldType(); //object value = row[e.ColumnIndex]; //DataRow row = ((DataRowView)Rows[e.RowIndex].DataBoundItem).Row; //object value = row[e.ColumnIndex, row.RowState == DataRowState.Deleted ? DataRowVersion.Original : DataRowVersion.Current]; //DataColumn col = row.Table.Columns[e.ColumnIndex]; string sval = null; string lookupVal = null; Bitmap icon = null; //Brush bg = Brushes.White; Brush fg = Brushes.Black; Brush lfg = m_lookupBrush; //if (e.RowIndex > 0 && e.RowIndex % 6 == 2) bg = NiceColorTable.OddRowBrush; //if (e.RowIndex > 0 && e.RowIndex % 6 == 5) bg = NiceColorTable.EvenRowBrush; switch (type) { case TypeStorage.Null: sval = "(NULL)"; fg = Brushes.Gray; //bg = Brushes.LightGray; break; case TypeStorage.ByteArray: { byte[] data = row.GetByteArray(); //sval = String.Format("BIN, {0}", Texts.Get("s_bytes$count", "count", data.Length)); sval = Texts.Get("s_bytes$count", "count", data.Length); icon = CoreIcons.picture; } break; default: { var fmt = DataSource.BedConvertor.Formatter; fmt.ReadFrom(row); sval = fmt.GetText(); } break; } if (GetLookupInfo != null && (type.IsNumber() || type == TypeStorage.String)) { m_lookupEventArgs.ColumnIndex = e.ColumnIndex; m_lookupEventArgs.RowIndex = e.RowIndex; m_lookupEventArgs.Value = sval; m_lookupEventArgs.LookupValue = null; GetLookupInfo(this, m_lookupEventArgs); if (m_lookupEventArgs.LookupValue != null) { lookupVal = m_lookupEventArgs.LookupValue; } } //if (value == null || value == DBNull.Value) //{ // sval = "(NULL)"; // bg = Brushes.LightGray; //} //else if (value is byte[]) //{ // byte[] data = (byte[])value; // //sval = String.Format("BIN, {0}", Texts.Get("s_bytes$count", "count", data.Length)); // sval = Texts.Get("s_bytes$count", "count", data.Length); // icon = CoreIcons.picture; //} //else if (!(value is bool)) //{ // sval = value.ToString(); // if (GetLookupInfo != null) // { // m_lookupEventArgs.ColumnIndex = e.ColumnIndex; // m_lookupEventArgs.Value = value; // m_lookupEventArgs.LookupValue = null; // GetLookupInfo(this, m_lookupEventArgs); // if (m_lookupEventArgs.LookupValue != null) // { // lookupVal = m_lookupEventArgs.LookupValue; // } // } //} string firstLine = null; if (sval != null) { if (sval.Contains("\n")) { string sval0 = sval; int lines = 1; foreach (char c in sval) { if (c == '\n') { lines += 1; } } //sval = String.Format("TEXT, {0}", Texts.Get("s_lines$count", "count", lines)); sval = Texts.Get("s_lines$count", "count", lines); fg = Brushes.Gray; icon = CoreIcons.text2; int pos = sval0.IndexOf('\n'); firstLine = sval0.Substring(0, pos).TrimEnd(); } } var ctype = DataGridCellType.Regular; if (e.ColumnIndex >= 0 && !ReadOnly) { switch (row.RowState) { case BedRowState.Added: ctype = DataGridCellType.AddedRow; break; case BedRowState.Deleted: case BedRowState.Detached: ctype = DataGridCellType.RemovedRow; break; case BedRowState.Modified: if (row.IsChanged(e.ColumnIndex)) { ctype = DataGridCellType.ModifiedCell; } else { ctype = DataGridCellType.ModifiedRow; } break; } } if (HightlightVisible && HighlightRow >= 0 && e.RowIndex == HighlightRow) { ctype = DataGridCellType.Highlight; } if (HightlightVisible && HighlightColumn >= 0 && e.ColumnIndex == HighlightColumn) { ctype = DataGridCellType.Highlight; } //if (CurrentCell.ColumnIndex == e.ColumnIndex && CurrentCell.RowIndex == e.RowIndex) if (Rows[e.RowIndex].Cells[e.ColumnIndex].Selected) { ctype = DataGridCellType.Selected; //bg = Brushes.Navy; fg = Brushes.White; lfg = m_lookupBrush; } style.PaintCellBackground(e, ctype); //e.Graphics.FillRectangle(bg, e.CellBounds); int dleft = 0; if (icon != null) { int dtop = (e.CellBounds.Height - icon.Height) / 2; e.Graphics.DrawImage(icon, new Rectangle(e.CellBounds.Left + 1, e.CellBounds.Top + dtop, icon.Width, icon.Height)); dleft = icon.Width + 1; } if (sval != null) { Rectangle r = e.CellBounds; r.X += e.CellStyle.Padding.Left + dleft; r.Width -= (e.CellStyle.Padding.Right + e.CellStyle.Padding.Left + dleft); r.Y += e.CellStyle.Padding.Top; r.Height -= (e.CellStyle.Padding.Bottom + e.CellStyle.Padding.Top); e.Graphics.DrawString(sval, Font, fg, r, m_gridTextFormat); if (lookupVal != null || firstLine != null) { SizeF s = e.Graphics.MeasureString(sval, Font); Rectangle rl = r; rl.X = r.Left + (int)s.Width + 3; rl.Width = r.Right - rl.Left; if (lookupVal != null) { e.Graphics.DrawString(lookupVal, Font, lfg, rl, m_gridTextFormat); } if (firstLine != null) { e.Graphics.DrawString(firstLine, Font, Brushes.Black, rl, m_gridTextFormat); } } } else { e.PaintContent(e.CellBounds); } if (row.RowState == BedRowState.Deleted) { int strikey = (e.CellBounds.Top + e.CellBounds.Bottom) / 2; var pen = Pens.Black; if ((e.State & DataGridViewElementStates.Selected) != 0) { pen = Pens.Yellow; } e.Graphics.DrawLine(pen, e.CellBounds.Left, strikey, e.CellBounds.Right, strikey); } e.Paint(e.CellBounds, DataGridViewPaintParts.Border); e.Handled = true; }