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 Data Binding / August 2008

Tip: Looking for answers? Try searching our database.

DataGridView BindingList keep sorted

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ondrej Medek - 30 Jul 2008 14:39 GMT
Hi,

I have IList<> of my objects bind to the DataGridView through
BindingList<>. I want to keep my List<> sorted according to my sort
order (i.e programatically set) when the user change add or delete
rows. So I catch some events form DGV and sort my list list. For
adding or deleting rows it works fine.

I have just a problem with event CellValueChanged. When I sort the
list in this event, then I cannot set current cell to the moved
position. I just find the right position, set the dgv.CurrentCell =
dgv[col, row]. But the current row stays in the old position. Where's
the problem? Should I observe another event?

I have one more question, is there any "straight" way to accomplish my
task? I have tried to implement SortableBindingList<> from MSDN
examples, but it does not keep list sorted. It just sorts the list
when the sorting is called programatically.

Thanks
Ondrej Medek - 06 Aug 2008 13:28 GMT
Hmm, it is strange, but the following code solved my problem:

       protected override bool ProcessDialogKey(Keys keyData)
       {
           Keys keyCode = (keyData & Keys.KeyCode);
           if (keyCode == Keys.Enter || keyCode == Keys.Tab)
           {
               return this.ProcessRightKey(keyData);
           }
           return base.ProcessDialogKey(keyData);
       }

       protected override bool ProcessDataGridViewKey(KeyEventArgs e)
       {
           if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab)
           {
               return this.ProcessRightKey(e.KeyData);
           }
           return base.ProcessDataGridViewKey(e);
       }

--
http://xmedeko.blogspot.com
Ondrej Medek - 06 Aug 2008 13:47 GMT
Ahh, it was this code plus setting CurrentCell in CellValueChanged
event. So, just to set CurrentCell in CellValueChanged didn't work
without the overriding ProcessDialogKey and ProcessDataGridViewKey.

--
http://xmedeko.blogspot.com

> Hmm, it is strange, but the following code solved my problem:
>
[quoted text clipped - 16 lines]
>             return base.ProcessDataGridViewKey(e);
>         }
Ondrej Medek - 07 Aug 2008 20:49 GMT
Yeah, the main tric is to change Tab to the Right Key, by
ProcessRightKey().

--
http://xmedeko.blogspot.com

> Ahh, it was this code plus setting CurrentCell in CellValueChanged
> event. So, just to set CurrentCell in CellValueChanged didn't work
[quoted text clipped - 22 lines]
> >             return base.ProcessDataGridViewKey(e);
> >         }

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.