HighTechTalks DotNet Forums  

DataGridView BindingList keep sorted

Dotnet Framework (WinForms DataBinding) microsoft.public.dotnet.framework.windowsforms.databinding


Discuss DataGridView BindingList keep sorted in the Dotnet Framework (WinForms DataBinding) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Ondrej Medek
 
Posts: n/a

Default DataGridView BindingList keep sorted - 07-30-2008 , 08:39 AM






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

Reply With Quote
  #2  
Old   
Ondrej Medek
 
Posts: n/a

Default Re: DataGridView BindingList keep sorted - 08-06-2008 , 07:28 AM






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

Reply With Quote
  #3  
Old   
Ondrej Medek
 
Posts: n/a

Default Re: DataGridView BindingList keep sorted - 08-06-2008 , 07:28 AM



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

Reply With Quote
  #4  
Old   
Ondrej Medek
 
Posts: n/a

Default Re: DataGridView BindingList keep sorted - 08-06-2008 , 07:47 AM



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

On 6 Srp, 14:28, Ondrej Medek <xmed... (AT) gmail (DOT) com> wrote:
Quote:
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);
* * * * }



Reply With Quote
  #5  
Old   
Ondrej Medek
 
Posts: n/a

Default Re: DataGridView BindingList keep sorted - 08-06-2008 , 07:47 AM



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

On 6 Srp, 14:28, Ondrej Medek <xmed... (AT) gmail (DOT) com> wrote:
Quote:
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);
* * * * }



Reply With Quote
  #6  
Old   
Ondrej Medek
 
Posts: n/a

Default Re: DataGridView BindingList keep sorted - 08-07-2008 , 02:49 PM



Yeah, the main tric is to change Tab to the Right Key, by
ProcessRightKey().

--
http://xmedeko.blogspot.com

On 6 Srp, 14:47, Ondrej Medek <xmed... (AT) gmail (DOT) com> wrote:
Quote:
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

On 6 Srp, 14:28, Ondrej Medek <xmed... (AT) gmail (DOT) com> wrote:

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);
* * * * }


Reply With Quote
  #7  
Old   
Ondrej Medek
 
Posts: n/a

Default Re: DataGridView BindingList keep sorted - 08-07-2008 , 02:49 PM



Yeah, the main tric is to change Tab to the Right Key, by
ProcessRightKey().

--
http://xmedeko.blogspot.com

On 6 Srp, 14:47, Ondrej Medek <xmed... (AT) gmail (DOT) com> wrote:
Quote:
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

On 6 Srp, 14:28, Ondrej Medek <xmed... (AT) gmail (DOT) com> wrote:

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);
* * * * }


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.