PC Review


Reply
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average.

DBGrid, CurrentRow. Easier way?

 
 
Chad Z. Hower aka Kudzu
Guest
Posts: n/a
 
      14th Feb 2005
CurrentSelectedIndex of course wont work - user can resort rows by clicking
on a column title and then index of the grid won't reflect the same order as
the bound data table.

Currently the code is doing this:

CurrencyManager xCM = (CurrencyManager)BindingContext[dgrdVendors.DataSource,
dgrdVendors.DataMember];
DataRowView xDRV = (DataRowView)xCM.Current;
_Vendor = (AdminWS.VendorListDS.VendorRow)xDRV.Row;

Just to get the matching row in the datatable for the currently selected row
in the datagrid. Is there an easier / shorter way I've overlooked?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      14th Feb 2005
Hi Kudzu,

How are you, we did a long time not see you here, (two days ago I saw you
again). For this you need the and the bindingmanager position.

http://msdn.microsoft.com/library/de...itiontopic.asp


or currencymanager position
http://msdn.microsoft.com/library/de...itiontopic.asp


By the way the clicked sorted column is reflected in the defaultview.sort
property

Quiet easy to use.

Cor


 
Reply With Quote
 
Chad Z. Hower aka Kudzu
Guest
Posts: n/a
 
      15th Feb 2005
"Cor Ligthert" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):
> How are you, we did a long time not see you here, (two days ago I saw
> you again). For this you need the and the bindingmanager position.


Thanks. Just been busy.

> http://msdn.microsoft.com/library/de...en-us/cpref/ht
> ml/frlrfsystemwindowsformsbindingmanagerbaseclasspositiontopic.asp
>
> or currencymanager position
> http://msdn.microsoft.com/library/de...en-us/cpref/ht
> ml/frlrfsystemwindowsformscurrencymanagerclasspositiontopic.asp


Not quiet.. The second one is a descendant of the first class, and merely
is an override.

Here is what we are using now - it does work even if the user resorts the
grid:
CurrencyManager xCM = (CurrencyManager)BindingContext[dataGrid1.DataSource,
dataGrid1.DataMember];
DataRowView xDRV = (DataRowView)xCM.Current;
AdminWS.AdminCartReadDS.CartRow xCart
= (AdminWS.AdminCartReadDS.CartRow)xDRV.Row;

However this is a lot of work just to get the current row. Im hoping there
is a shorter way - and that its not just another example of .NET being
overengineered without the appropriate "practical" short cut being added.

According to your post, this should work:
CurrencyManager xCM = (CurrencyManager)BindingContext[dataGrid1.DataSource,
dataGrid1.DataMember];
AdminWS.AdminCartReadDS.CartRow xCart
= ((AdminWS.AdminCartReadDS.CartDataTable)dataGrid1.DataSource)
[xCM.Position];

But:
1) Thats still way to much to get the current row.
2) It works - only until the user sorts the grid, which is the same result
as using the position from the grid directly. Unsorted it works -but not
sorted. Sorted rearranges the grid - but not the datatable of course.
CurrencyManager.Position seems to refer to the same as the grid row index.

There SHOULD be something like
RowType xRow = (RowType)grid.something.currentrow

There probably isnt - although there should be. But even in .NET there
should be SOMETHING shorter than what we are currently doing.

> By the way the clicked sorted column is reflected in the
> defaultview.sort property


Yes, but unless I resort the underlying datatable.. which is not only hack,
but has bad side effects.

> Quiet easy to use.


Is it? What am I missing?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
 
Reply With Quote
 
Dmitriy Lapshin [C# / .NET MVP]
Guest
Posts: n/a
 
      15th Feb 2005
Chad,

Your approach with DataRowView is absolutely correct. Yes, it is cumbersome,
but it is the best working one. You can create an inherited control which
would implement a kind of 'CurrentDataRow' property based on your code
snippet.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Chad Z. Hower aka Kudzu" <(E-Mail Removed)> wrote in message
news:Xns95FDD79A1639cpub@127.0.0.1...
> "Cor Ligthert" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>> How are you, we did a long time not see you here, (two days ago I saw
>> you again). For this you need the and the bindingmanager position.

>
> Thanks. Just been busy.
>
>> http://msdn.microsoft.com/library/de...en-us/cpref/ht
>> ml/frlrfsystemwindowsformsbindingmanagerbaseclasspositiontopic.asp
>>
>> or currencymanager position
>> http://msdn.microsoft.com/library/de...en-us/cpref/ht
>> ml/frlrfsystemwindowsformscurrencymanagerclasspositiontopic.asp

>
> Not quiet.. The second one is a descendant of the first class, and merely
> is an override.
>
> Here is what we are using now - it does work even if the user resorts the
> grid:
> CurrencyManager xCM =
> (CurrencyManager)BindingContext[dataGrid1.DataSource,
> dataGrid1.DataMember];
> DataRowView xDRV = (DataRowView)xCM.Current;
> AdminWS.AdminCartReadDS.CartRow xCart
> = (AdminWS.AdminCartReadDS.CartRow)xDRV.Row;
>
> However this is a lot of work just to get the current row. Im hoping there
> is a shorter way - and that its not just another example of .NET being
> overengineered without the appropriate "practical" short cut being added.
>
> According to your post, this should work:
> CurrencyManager xCM =
> (CurrencyManager)BindingContext[dataGrid1.DataSource,
> dataGrid1.DataMember];
> AdminWS.AdminCartReadDS.CartRow xCart
> = ((AdminWS.AdminCartReadDS.CartDataTable)dataGrid1.DataSource)
> [xCM.Position];
>
> But:
> 1) Thats still way to much to get the current row.
> 2) It works - only until the user sorts the grid, which is the same result
> as using the position from the grid directly. Unsorted it works -but not
> sorted. Sorted rearranges the grid - but not the datatable of course.
> CurrencyManager.Position seems to refer to the same as the grid row index.
>
> There SHOULD be something like
> RowType xRow = (RowType)grid.something.currentrow
>
> There probably isnt - although there should be. But even in .NET there
> should be SOMETHING shorter than what we are currently doing.
>
>> By the way the clicked sorted column is reflected in the
>> defaultview.sort property

>
> Yes, but unless I resort the underlying datatable.. which is not only
> hack,
> but has bad side effects.
>
>> Quiet easy to use.

>
> Is it? What am I missing?
>
>
> --
> Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
> "Programming is an art form that fights back"
>
> Empower ASP.NET with IntraWeb
> http://www.atozed.com/IntraWeb/


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      15th Feb 2005
Kudzu,

Does this sample that I made for you show what is in my opinion an easier
way, works when the user pushes the sort in the datagrid as well.. Try it?

\\\needs a datagrid and a button. The load event is to fill the datatable.
private void Form2_Load(object sender,
System.EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("kudzu");
for (int i = 0;i<10;i++)
{
dt.Rows.Add(dt.NewRow());
dt.Rows[i]["kudzu"] = i.ToString();
}
dataGrid1.DataSource = dt.DefaultView;
}
private void button1_Click(object sender,
System.EventArgs e)
{
DataRowView xDRV = ((DataView)dataGrid1.DataSource)
[((CurrencyManager)BindingContext
[dataGrid1.DataSource]).Position];

MessageBox.Show(xDRV[0].ToString());
}

I hope this helps a little bit?

Cor


 
Reply With Quote
 
Chad Z. Hower aka Kudzu
Guest
Posts: n/a
 
      15th Feb 2005
"Dmitriy Lapshin [C# / .NET MVP]" <x-(E-Mail Removed)> wrote
in news:#(E-Mail Removed):
> Your approach with DataRowView is absolutely correct. Yes, it is
> cumbersome, but it is the best working one. You can create an inherited


This really sucks. This and many other items unfortunately seems to
demonstrate those at MS dreaming this stuff up arent actually using it in
real practice....

> control which would implement a kind of 'CurrentDataRow' property based
> on your code snippet.


Yes, thats what I planned to do. We shouldnt have to do such things for such
trivial functionality that should be native though.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
 
Reply With Quote
 
Chad Z. Hower aka Kudzu
Guest
Posts: n/a
 
      15th Feb 2005
"Cor Ligthert" <(E-Mail Removed)> wrote in news:OqMp1J1EFHA.3244
@TK2MSFTNGP15.phx.gbl:
> Does this sample that I made for you show what is in my opinion an easier
> way, works when the user pushes the sort in the datagrid as well.. Try


> DataRowView xDRV = ((DataView)dataGrid1.DataSource)
> [((CurrencyManager)BindingContext
> [dataGrid1.DataSource]).Position];


Its not much shorter unfortunately. Its still like taking a 747 to the
grocery store for milk...


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      15th Feb 2005
Kudzu,
>
> Its not much shorter unfortunately. Its still like taking a 747 to the
> grocery store for milk...
>


It is *shorter* and works while the user pushes the sort header.

I miss the relation to a 747. Why do you want to use that to go to a grocery
store for milk.

You told you was now in the US. You don't need that there, you just can go
to a shop mostly by car however sometimes by feet.

:-)

Cor


 
Reply With Quote
 
Chad Z. Hower aka Kudzu
Guest
Posts: n/a
 
      15th Feb 2005
"Cor Ligthert" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):
> It is *shorter* and works while the user pushes the sort header.


Not much shorter - the other version can be smashed up into one line too.


> I miss the relation to a 747. Why do you want to use that to go to a
> grocery store for milk.


Exactly. Doing so is like trying to get the current data row for a grid in
WinForms. It should be much easier...

> You told you was now in the US. You don't need that there, you just can
> go to a shop mostly by car however sometimes by feet.


Yes still in the US visiting - really home sick but family situation
requires me to stay some more.

He - you have no idea... I cant stand it here. I like to drive - but I
really HATE driving EVERYWHERE. I like it much better at home where I only
need a car occasionally and not for daily shopping... Aside from New York
or so, American cities arent built for walking....

In fact, compared to Europe getting a loaf of bread here is like getting a
current row from WinForms.




--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set currentRow in dgv dbuchanan Microsoft Dot NET Framework Forms 9 26th Oct 2007 02:24 AM
Same CurrentRow in Datagrid as before... P Dietz Microsoft VB .NET 1 21st Oct 2003 08:40 PM
CurrentRow in Datagrid - always the first :-( dr. p. dietz Microsoft Dot NET Framework Forms 1 8th Sep 2003 11:59 AM
Re: How to get the currentrow from the grid Ernest Morariu Microsoft C# .NET 0 29th Jul 2003 03:51 PM
Re: How to get the currentrow from the grid MB Microsoft C# .NET 0 28th Jul 2003 07:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:03 AM.