Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / July 2007

Tip: Looking for answers? Try searching our database.

DataGridView pencil and row editing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
imran.a - 26 Jul 2007 09:36 GMT
Hi,
The datagridview control is rather confusing when it comes to editing rows.
I have a datagridview control bound to a dataset (exposed through a
bindingsource). The edit mode is set to edit on key stroke. The problem is
that when you begin editing a cell for a given row the pencil glyph will
appear in the row header. If you move in to the next cell for the same row
(tab or right arrow key for example) it would appear that you are no longer
in edit mode as the pencil disappears and an arrow is shown in the
corresponding row header. However, although you are no longer editing a cell
the row remains in 'edit mode' (i.e the underlying data set row has pending
proposed changes).

This is very confusing for users especially with large datasets as it is
very easy to edit a cell and then attempt to save your changes only to find
that they were not committed. Off course if you remember to hit enter every
time you edit a cell you can be sure that each change is committed to the
dataset however, there are no visual cues which indicate to the user that the
current row is dirty.

Is there any way I can show the pencil glyph in the row header as long as
the current row is being edited? I cant seem to find any useful row events to
hook in to (the cell has begin and endedit but there is nothing similar for
rows) to achieve this.

Thanks in advance.

Imran
ClayB - 28 Jul 2007 09:45 GMT
You can draw it your self. Handle CellBeginEdit to set a flag when the
row starts editing. Test this flag in CellPainting and draw the icon
when needed. Then reset the flag in CurrentCellChanged when you move
off the row.

       private int editingRowIndex = int.MinValue;
       void dataGridView1_CellBeginEdit(object sender,
DataGridViewCellCancelEventArgs e)
       {
           editingRowIndex = e.RowIndex;
       }
       void dataGridView1_CurrentCellChanged(object sender, EventArgs
e)
       {
           if (dataGridView1.CurrentCell.RowIndex != editingRowIndex)
           {
               editingRowIndex = int.MinValue;
           }
       }
       void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
       {
           if (e.ColumnIndex == -1 && e.RowIndex == editingRowIndex)
           { //drawing row header
               e.Paint(e.ClipBounds, DataGridViewPaintParts.All);
               Rectangle rect = e.CellBounds;
               rect.X += 4;//move in a little
               rect.Width = 16;
               e.Graphics.DrawIcon(pencilIcon, rect);
               e.Handled = true;
           }
       }

=====================
Clay Burch
Syncfusion, Inc.
imran.a - 30 Jul 2007 20:04 GMT
Thanks Clay I will try this out. Any idea where I can find the pencil icon or
will I have to add my own icon file.

Thanks,

Imran

> You can draw it your self. Handle CellBeginEdit to set a flag when the
> row starts editing. Test this flag in CellPainting and draw the icon
[quoted text clipped - 32 lines]
> Clay Burch
> Syncfusion, Inc.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.