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

  • Thread starter Kris Bethea via DotNetMonster.com
  • Start date
K

Kris Bethea via DotNetMonster.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
 
B

Bob Grommes

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.DataSource,dgdContactInfo.DataMember),CurrencyManager)

Converting this to C# you would get:

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

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

dr = dv[cm.Position].Row;

Hope this helps.

--Bob
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top