Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 9th, 2007, 03:11 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default 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>
__________________
Rob
http://cantgrokwontgrok.blogspot.com
 
Old September 9th, 2007, 04:11 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

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>
 
Old September 9th, 2007, 04:28 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

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>





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Set the Selection in Dropdownlist Control akhilhp ASP.NET 2.0 Basics 3 May 27th, 2007 07:13 AM
Set window position using button blkskullwork Javascript 5 January 18th, 2007 04:51 PM
How to set cursor position in a textbox? zayasv VB.NET 2 April 29th, 2006 07:09 AM
Set Default selection in ListBox nmreid Classic ASP Basics 0 January 20th, 2006 04:49 PM





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