473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VB.NET to C# (CurrencyManager related) ???

Greetings,
I have a VB.NET program that I am trying to convert to C# (my office
decided that we are going to use C# from now on).

I've only been working with C# for about a month now, so this has been
quite the learning experience for me.

The following code is from my VB.NET program and it selects the Call Number
from my datagrid and then uses that information to populate another form.

I cannot seem to find the appropriate adjustment for the CurrencyManager
to reproduce the effect in C#.

Could someone please help me?

Thanks,
Kris
Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSelect.Click
Dim cm As CurrencyManager = CType(Me.BindingContext
(dgdContactInfo.DataSource, dgdContactInfo.DataMember), CurrencyManager)

' Retrieve the default DataView of the DataGrid
Dim dv As DataView = CType(cm.List, DataView)

Dim dr As DataRow
dr = dv.Item(cm.Position).Row
strCallNumber = dr("Call Number")
myForm.CallNumber = strCallNumber
myForm.Show()
Me.Hide()
End Sub

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #1
4 2790
Well "Me" in VB = "this" in C#, both are implied by context and so including
them is a matter of preference or clarity.

CType() in VB doesn't have an exact equivalent in C#, however, you could
have as easily used DirectCast() which is somewhat faster than CType()
anyway and that is exactly equivalent to C# casts:

Dim cm As Currency Manager =
DirectCast(BindingContext(dgdContactInfo.DataSourc e,dgdContactInfo.DataMember),CurrencyManager)

Converting this to C# you would get:

Currency Manager cm =
(CurrencyManager)BindingContext(dgdContactInfo.Dat aSource,dgdContactInfo.DataMember)

Later on, you can substitute the indexer for the Item property:

dr = dv[cm.Position].Row;

Hope this helps.

--Bob

"Kris Bethea via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:66******************************@DotNetMonste r.com...
Greetings,
I have a VB.NET program that I am trying to convert to C# (my office
decided that we are going to use C# from now on).

I've only been working with C# for about a month now, so this has been
quite the learning experience for me.

The following code is from my VB.NET program and it selects the Call
Number
from my datagrid and then uses that information to populate another form.

I cannot seem to find the appropriate adjustment for the CurrencyManager
to reproduce the effect in C#.

Could someone please help me?

Thanks,
Kris
Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSelect.Click
Dim cm As CurrencyManager = CType(Me.BindingContext
(dgdContactInfo.DataSource, dgdContactInfo.DataMember), CurrencyManager)

' Retrieve the default DataView of the DataGrid
Dim dv As DataView = CType(cm.List, DataView)

Dim dr As DataRow
dr = dv.Item(cm.Position).Row
strCallNumber = dr("Call Number")
myForm.CallNumber = strCallNumber
myForm.Show()
Me.Hide()
End Sub

--
Message posted via http://www.dotnetmonster.com

Nov 16 '05 #2
The following was obtained with our Instant C# VB.NET to C# converter.
Our Demo Edition is available at www.instantcsharp.com and is fully supported.

//TODO: INSTANT C# TODO TASK: Insert the following converted event handlers
at the end of the 'InitializeComponent' method for forms or into a
constructor for other classes:
btnSelect.Click += new System.EventHandler(btnSelect_Click);

private void btnSelect_Click(object sender, System.EventArgs e)
{
CurrencyManager cm =
(CurrencyManager)(this.BindingContext[dgdContactInfo.DataSource,
dgdContactInfo.DataMember]);

// Retrieve the default DataView of the DataGrid
DataView dv = (DataView)(cm.List);

DataRow dr = null;
dr = dv[cm.Position].Row;
strCallNumber = dr["Call Number"];
myForm.CallNumber = strCallNumber;
myForm.Show();
this.Hide();
}
Regards,
David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter

"Kris Bethea via DotNetMonster.com" wrote:
Greetings,
I have a VB.NET program that I am trying to convert to C# (my office
decided that we are going to use C# from now on).

I've only been working with C# for about a month now, so this has been
quite the learning experience for me.

The following code is from my VB.NET program and it selects the Call Number
from my datagrid and then uses that information to populate another form.

I cannot seem to find the appropriate adjustment for the CurrencyManager
to reproduce the effect in C#.

Could someone please help me?

Thanks,
Kris
Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSelect.Click
Dim cm As CurrencyManager = CType(Me.BindingContext
(dgdContactInfo.DataSource, dgdContactInfo.DataMember), CurrencyManager)

' Retrieve the default DataView of the DataGrid
Dim dv As DataView = CType(cm.List, DataView)

Dim dr As DataRow
dr = dv.Item(cm.Position).Row
strCallNumber = dr("Call Number")
myForm.CallNumber = strCallNumber
myForm.Show()
Me.Hide()
End Sub

--
Message posted via http://www.dotnetmonster.com

Nov 16 '05 #3
Thanks! That was a great help!

Kris

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #4
That's an awesome resource!
Thanks for your help! :)

Kris

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pete Davis | last post by:
I have written a custom databound grid control that we've been using successfully for months, but one of our developers has just run into a problem that I can't figure out. The code for setting...
2
by: web1110 | last post by:
I created a class derived from a DataGridTextBoxColumn. I have it working through looking at various examples on the net. To update the underlying DataGrid, I had to overload the Edit method...
1
by: Christopher Weaver | last post by:
When I add a row to my DataTable my CurrencyManager doesn't know it's there. I have a ComboBox and a CurrencyManager bound to a DataTable such that a selection within the ComboBox causes all...
10
by: D | last post by:
hi I have a form with 2 datagrids showing related table data in a master / child or order / order details type relationship. I would like to auto select the row in the order details table which...
4
by: Jeremy | last post by:
I have a dataset containing 2 tables. A is the master table, B is a lookup table. There is a combobox bound to B, which updates a value in a FK field in A. my currencymanager is created thus:...
2
by: Rich | last post by:
Hello, I have a datagrid (dgr1) on a form and I'm trying to bind a currencyManager Object (cma) to it and print the current row position. But all I get for cma.Position is 0, 0, 0 for any row...
3
by: Brian Richardson | last post by:
Hi, Please can anyone kindly offer some suggestions as to why the CurrencyManager might not refresh. I am using the CurrencyManager to navigate through a DataView. I am aware that there is...
2
by: Rich | last post by:
Hello, Following an example at http://www.vb-tips.com/dbpages.aspx?IA=DG (by Cor Lightert and Ken Tucker) on binding a dataRelation to a Datagridview for sqlClient, I was able to view rows...
0
by: polocar | last post by:
Hi, I have noticed a strange behaviour of CurrencyManager objects in C# (I use Visual Studio 2005 Professional Edition). Suppose that you have a SQL Server database with 2 tables called "Cities"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.