Re: Custom controls in datagrid
From: Ernest Morariu (ernest_at_gesora.com)
Date: 06/03/04
- Next message: CJ: "Re: Custom controls in datagrid"
- Previous message: Yoav Ben-Yosef: "Property in user control not visible in prop list"
- In reply to: CJ: "Re: Custom controls in datagrid"
- Next in thread: CJ: "Re: Custom controls in datagrid"
- Reply: CJ: "Re: Custom controls in datagrid"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 3 Jun 2004 17:04:58 +0200
I verified the class using just one column of that type , the others was of
different types.
I think that you can resolve this associating an event handler to the Leave
event of your RichTextDragBox control(you use inside the column)
In this event handler write something like :
this.rtdb.Hide();
I am not sure that this is the right solution .
Ernest
"CJ" <cjohns@telkomsa.net> wrote in message
news:MPG.1b2927c22f278b55989696@news.telkomsa.net...
> In article <#K#3GcISEHA.2936@TK2MSFTNGP12.phx.gbl>, ernest@gesora.com
> says...
> > I have made some changes :
>
> Thanks, that helps a lot :-)
>
> But there's still one issue: if I type in the right-hand column new row,
> and then click in the left-hand column of the same row, commit is not
> called. If I do this in reverse, ie. left column then right column, it
> works perfectly.
>
> Is there some intrinsic ordering to the columns?
>
> Interestingly, if I make one column my custom columnstyle, but leave the
> other as the standard TextBoxColumn, it all works fine.
>
>
>
> > 1. I changed the RichTextDragBox in RichTextBox to have the possibility
to
> > make tests.
> >
> > 2. In the Edit method ,at the begining I added:
> > if(this.isEditing )
> > {
> > this.rtdb.Focus();
> > return ;
> > }
> > When you type the first character on a new row, the framework calls the
Edit
> > for the second time(when the isEditing is already true) , without
calling
> > Commit first.
> > 3. In the Edit method :
> > rtdb.Bounds=bounds;
> > to make the rtdb to occupie all the surface of the cell.
> > 4. In the Edit method :
> > I changed the position of the :
> > rtdb.TextChanged += new EventHandler(RichTextBoxChanged);
> > to the end of the method.
> > In the old version you associated the event handler and then rtdb.Text =
> > val. That made to fire the event RichTextBoxChanged and the row apeared
as
> > "modified" when it got the focus and , in fact, it isn't modified.
> >
> > 5. in the event handler RichTextBoxChanged I added:
> > rtdb.TextChanged -= new EventHandler(RichTextBoxChanged)
> > The code in this event handler needs to executed just once at any new
> > editing session. In the old version, you executed this code at any
character
> > pressed on the keyboard.
> >
> > This is the new version of your class :
> >
////////////////////////////////////////////////////////////////////////////
> > /////////////////////////////////////////////
> > using System.Windows.Forms ;
> > using System.Drawing ;
> > using System;
> > using System.Diagnostics ;
> > namespace ExtendedDataGrid.ColumnStyles
> > {
> > public class DataGridRichTextBoxColumn : DataGridTextBoxColumn
> > {
> > public RichTextBox rtdb = new RichTextBox();
> > // The isEditing field tracks whether or not the user is
> > // editing data with the hosted control.
> > private bool isEditing;
> >
> > public DataGridRichTextBoxColumn() : base()
> > {
> > rtdb.Visible = false;
> > this.NullText = "";
> > }
> > protected override void Abort(int rowNum)
> > {
> > isEditing = false;
> > rtdb.TextChanged -= new EventHandler
> > (RichTextBoxChanged);
> > Invalidate();
> > }
> > protected override bool Commit(CurrencyManager dataSource,
> > int rowNum)
> > {
> > Console.WriteLine("Commit");
> > rtdb.Bounds = Rectangle.Empty;
> > rtdb.TextChanged -= new EventHandler
> > (RichTextBoxChanged);
> > if (!isEditing)
> > return true;
> > isEditing = false;
> > try
> > {
> > string val = rtdb.Text;
> > SetColumnValueAtRow(dataSource, rowNum, val);
> > }
> > catch (Exception)
> > {
> > Abort(rowNum);
> > return false;
> > }
> > Invalidate();
> > return true;
> > }
> > protected override void Edit(CurrencyManager source, int
> > rowNum, Rectangle bounds,
> > bool readOnly, string instantText, bool
> > cellIsVisible)
> > {
> > if(this.isEditing )
> > {
> > this.rtdb.Focus();
> > return ;
> > }
> > string val;
> > object o = GetColumnValueAtRow(source, rowNum);
> > if (Convert.IsDBNull(o))
> > val = this.NullText;
> > else
> > val = (string)o;
> > Console.WriteLine("IT: _" + instantText + "_ val: "
> > + val);
> > if (cellIsVisible)
> > {
> > // rtdb.Bounds = new Rectangle
> > // (bounds.X + 2, bounds.Y + 2,
> > // bounds.Width - 4, bounds.Height - 4);
> > rtdb.Bounds=bounds;
> > rtdb.Text = val;
> > rtdb.Visible = true;
> > rtdb.BringToFront();
> > rtdb.Focus();
> > }
> > else
> > {
> > rtdb.Text = val;
> > rtdb.Visible = false;
> > }
> > if (rtdb.Visible)
> > DataGridTableStyle.DataGrid.Invalidate
> > (bounds);
> > rtdb.TextChanged += new EventHandler
> > (RichTextBoxChanged);
> > }
> > private void RichTextBoxChanged(object sender,
> > System.EventArgs e)
> > {
> > Console.WriteLine("DragBoxChanged");
> > this.isEditing = true;
> > base.ColumnStartedEditing(rtdb);
> > rtdb.TextChanged -= new EventHandler
> > (RichTextBoxChanged);
> > }
> > protected override Size GetPreferredSize(Graphics g, object
> > val)
> > {
> > return new Size(100, rtdb.PreferredHeight + 4);
> > }
> > protected override int GetMinimumHeight()
> > {
> > return rtdb.PreferredHeight + 4;
> > }
> > protected override int GetPreferredHeight(Graphics g,
> > object val)
> > {
> > return rtdb.PreferredHeight + 4;
> > }
> > protected override void Paint(Graphics g, Rectangle bounds,
> > CurrencyManager source, int rowNum)
> > {
> > Paint(g, bounds, source, rowNum, false);
> > }
> > protected override void Paint(Graphics g, Rectangle bounds,
> > CurrencyManager source,
> > int rowNum, bool alignToRight)
> > {
> > Paint(g,bounds, source, rowNum, Brushes.Red,
> > Brushes.Blue, alignToRight);
> > }
> > protected override void Paint(Graphics g, Rectangle bounds,
> > CurrencyManager source,
> > int rowNum, Brush backBrush, Brush foreBrush, bool
> > alignToRight)
> > {
> > string val;
> > object o = GetColumnValueAtRow(source, rowNum);
> > if (Convert.IsDBNull(o))
> > val = this.NullText;
> > else
> > val = (string)o;
> > Rectangle rect = bounds;
> > g.FillRectangle(backBrush,rect);
> > rect.Offset(0, 2);
> > rect.Height -= 2;
> > g.DrawString(val,
> > this.DataGridTableStyle.DataGrid.Font, foreBrush, rect);
> > }
> > protected override void SetDataGridInColumn(DataGrid val)
> > {
> > base.SetDataGridInColumn(val);
> > if (rtdb.Parent != null)
> > {
> > rtdb.Parent.Controls.Remove(rtdb);
> > }
> > if (val != null)
> > {
> > val.Controls.Add(rtdb);
> > }
> > }
> > }
> > }
> >
////////////////////////////////////////////////////////////////////////////
> > ///////////////////////////////////////////////////////////////
> > Ernest
> >
> >
> >
>
> --
> CJ
- Next message: CJ: "Re: Custom controls in datagrid"
- Previous message: Yoav Ben-Yosef: "Property in user control not visible in prop list"
- In reply to: CJ: "Re: Custom controls in datagrid"
- Next in thread: CJ: "Re: Custom controls in datagrid"
- Reply: CJ: "Re: Custom controls in datagrid"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|