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 / November 2005

Tip: Looking for answers? Try searching our database.

dataview, which row is selected

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul Wohlhart - 25 Nov 2005 13:03 GMT
hi

i'm a complete newby to the adonet stuff. so i'm facing beginner problems.

i have a DataGrid bound to a table called data

    dataGrid.DataSource = data;

data gets filled by a DataAdapter da

    da.fill(data);

the table has two rows: "id" and "name".
since i inserted a TableStyle to the DataGrid the grid shows
only the "name".

now if someone clicks the "name" i need to the matching "id".
(shouldn't this be damn simple?)

The only thing i found is dataGrid.CurrentCell.RowNumber which
for sure is just the number of the row in the dataGrid,
not in the Table. Isn't there something like a
cursor/current-/active-cell/row in the Tabel that gets updated when
i click on a row in the DataGrid?

thanks,
paul
Bart Mermuys - 25 Nov 2005 13:26 GMT
Hi,

> hi
>
[quoted text clipped - 20 lines]
> cursor/current-/active-cell/row in the Tabel that gets updated when
> i click on a row in the DataGrid?

A question that has been asked many times.

You have to know that even when you bind a DataTable to a DataGrid it
actually uses a DataView internally.  A DataTable isn't directly bindable
nor sortable while a DataView is both.

A CurrencyManager manages a list binding and the position, you can get the
relevant CurrencyManager using BindingContext[...].  A CurrencyManager
exposes some usefull properties:
- Position ( = CurrentRowIndex )
- List ( = DataView)
- Current ( = DataRowView).

Now, it's possible to get the value for id from the Current DataRowView:

public void ShowCurrentId()
{
 DataRowView currentDRV = (DataRowView)
    BindingContext[dataGrid1.DataSource, dataGrid1.DataMember].Current;

  Console.WriteLine( currentDRV["id"] );
}

HTH,
Greetings

> thanks,
> paul
Paul Wohlhart - 25 Nov 2005 13:54 GMT
> A question that has been asked many times.

I thought so. Obviously the msdn lacks an easy to find pointer to those
things or people like me are to dumb to find them.

CurrencyManager was the keyword, now i got it.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbco
nconsumersofdataonwindowsforms.asp


> HTH,
> Greetings

sure that helps.
you're kind of hyperactive in here. great work, keep it up
and thanks a lot.

paul
Bart Mermuys - 25 Nov 2005 14:36 GMT
Hi Paul,

>> A question that has been asked many times.
>
> I thought so. Obviously the msdn lacks an easy to find pointer to those
> things or people like me are to dumb to find them.

I wasn't really implying anthing, but i agree it could be more documented.

> CurrencyManager was the keyword, now i got it.
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbco
nconsumersofdataonwindowsforms.asp

Don't forget the other stuff about the DataView/DataRowView i mentioned.

>> HTH,
>> Greetings
>
> sure that helps.
> you're kind of hyperactive in here. great work, keep it up

I'll try.

> and thanks a lot.

You're welcome.

Greetings

> paul

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.