p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# (http://p2p.wrox.com/forumdisplay.php?f=22)
-   -   Set Form DataSet Position to DataGrid Selection (http://p2p.wrox.com/showthread.php?t=61887)

robzyc September 9th, 2007 03:11 AM

Set Form DataSet Position to DataGrid Selection
 
Hi All,

I am trying to implement the above, and would really appreciate some help as I am stuck!

I have a tabbed form, on one tab, we have the "data entry" stuff, text boxes, combos etc, and on the other tab is "search" stuff, which is basically a DataGrid which can be filtered and sorted etc.

What I am trying to do is allow the user to select a record in the DataGrid, and then set the Forms CurrencyManager position to the same record, so they can then edit the records values.

I have tried searching both Google and P2P but to no avail :(

Any help/pointers gratefully received,

Best Regards,

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>

robzyc September 9th, 2007 04:11 AM

Hi All,

OK, Here's what I have so far. The problem I had was getting the Selected DataSet Position in the GridView. I have been able to get the code working by using a DataView (with a DataSource of the same DataSet as the Form) for the DataGrid DataSource. I then pulled the position from the DataGrid by searching for the ID in the DataView. I then siply set the Form's BindingContext to the same position.

Here's my current code:
Code:

// Get the currently Selected ID from the DataGrid.
const int ID_COL_IDX = 0;
int rowIdx = dataGrid.CurrentRowIndex;               
long SelID = (long)dataGrid[rowIdx, ID_COL_IDX];

// Find the ID in the DataView and Set the Form DataSet Position
int dvPos = dataView1.Find(SelID);
this.BindingContext[dsRegister, "Student"].Position = dvPos;

If anyone has any other solutions then I'd love to hear them!

Thanks,

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>

robzyc September 9th, 2007 04:28 AM

Another Update!

Found a (IMO) much better way of doing it! :D
Code:

// Set the Current Student to the Student Selected in the DataView.
this.BindingContext[dsRegister, "Student"].Position =
this.BindingContext[dsRegister.Student].
Position;

// Set the Tab to the Entry Form
Tabs.SelectedTab = EntryTab;

How much simpler is that?! =D No DataView or anything..

I think its quite cool that the currency managers really do Manage!

Maybe they should get into consulting for managers at work ;)

Hope this helps others!

Best Regards,

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>


All times are GMT -4. The time now is 08:23 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.