//
//
-// NOT COMPLETE
-
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
private IFormatProvider format_provider = null;
private StringFormat string_format = new StringFormat ();
private DataGridTextBox textbox;
- private static readonly int offset_x = 0;
- private static readonly int offset_y = 0;
+ private static readonly int offset_x = 2;
+ private static readonly int offset_y = 2;
#endregion // Local Variables
#region Constructors
return true;
try {
- object obj = GetColumnValueAtRow (dataSource, rowNum);
- string existing_text = GetFormattedString (obj);
+ string existing_text = GetFormattedValue (dataSource, rowNum);
if (existing_text != textbox.Text) {
if (textbox.Text == NullText)
textbox.TextAlign = alignment;
- if ((ParentReadOnly == true) ||
- (ParentReadOnly == false && ReadOnly == true) ||
- (ParentReadOnly == false && _ro == true)) {
- textbox.ReadOnly = true;
- } else {
- textbox.ReadOnly = false;
- }
-
- if (instantText != null && instantText != "") {
+ bool ro = false;
+
+ ro = (TableStyleReadOnly || ReadOnly || _ro);
+
+ if (!ro && instantText != null) {
textbox.Text = instantText;
}
else {
- object obj = GetColumnValueAtRow (source, rowNum);
- if (obj == null)
- textbox.Text = "";
- else
- textbox.Text = GetFormattedString (obj);
+ textbox.Text = GetFormattedValue (source, rowNum);
}
- textbox.Location = new Point (bounds.X + offset_x, bounds.Y + offset_y);
- textbox.Size = new Size (bounds.Width - offset_x, bounds.Height - offset_y);
-
- textbox.IsInEditOrNavigateMode = true;
+ textbox.ReadOnly = ro;
+ textbox.Bounds = new Rectangle (new Point (bounds.X + offset_x, bounds.Y + offset_y),
+ new Size (bounds.Width - offset_x, bounds.Height - offset_y));
+ textbox.IsInEditOrNavigateMode = ro || instantText == null;
textbox.Visible = cellIsVisible;
textbox.Focus ();
textbox.SelectAll ();
return FontHeight + 3;
}
- [MonoTODO]
protected internal override int GetPreferredHeight (Graphics g, object value)
{
- throw new NotImplementedException ();
+ string text = GetFormattedValue (value);
+ System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("/\r\n/");
+ int lines = r.Matches (text).Count;
+ return this.DataGridTableStyle.DataGrid.Font.Height * (lines+1) + 1;
}
- [MonoTODO]
protected internal override Size GetPreferredSize (Graphics g, object value)
{
- throw new NotImplementedException ();
+ string text = GetFormattedValue (value);
+ Size s = Size.Ceiling (g.MeasureString (text, this.DataGridTableStyle.DataGrid.Font));
+ s.Width += 4;
+ return s;
}
[MonoTODO]
protected internal override void Paint (Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
{
- object obj;
- obj = GetColumnValueAtRow (source, rowNum);
-
- PaintText (g, bounds, GetFormattedString (obj), backBrush, foreBrush, alignToRight);
+ PaintText (g, bounds, GetFormattedValue (source, rowNum), backBrush, foreBrush, alignToRight);
}
protected void PaintText (Graphics g, Rectangle bounds, string text, bool alignToRight)
protected internal override void UpdateUI (CurrencyManager source, int rowNum, string instantText)
{
-
+ if (textbox.Visible // I don't really like this, but it gets DataGridTextBoxColumnTest.TestUpdateUI passing
+ && textbox.IsInEditOrNavigateMode) {
+ textbox.Text = GetFormattedValue (source, rowNum);
+ }
+ else {
+ textbox.Text = instantText;
+ }
}
#endregion // Public Instance Methods
#region Private Instance Methods
- private string GetFormattedString (object obj)
+ private string GetFormattedValue (CurrencyManager source, int rowNum)
{
- if (obj == null)
- return "";
+ object obj = GetColumnValueAtRow (source, rowNum);
+ return GetFormattedValue (obj);
+ }
- if (obj == DBNull.Value)
+ private string GetFormattedValue (object obj)
+ {
+ if (DBNull.Value.Equals(obj) || obj == null)
return NullText;
- if (format != null && obj as IFormattable != null) {
+ if (format != null && format != String.Empty && obj as IFormattable != null)
return ((IFormattable)obj).ToString (format, format_provider);
- }
return obj.ToString ();