473,698 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to convert C# to VB

I want to change this Class to VB.NET Class, can you help me ?

using System;

using System.Windows. Forms;

using System.Drawing;

using System.Data;

using System.Diagnost ics;

namespace DataGridDemo

{

// Derive class from DataGridTextBox Column

public class DataGridComboBo xColumn : DataGridTextBox Column

{

// Hosted ComboBox control

private ComboBox comboBox;

private CurrencyManager cm;

private int iCurrentRow;
// Constructor - create combobox, register selection change event handler,

// register lose focus event handler

public DataGridComboBo xColumn()

{

this.cm = null;

// Create ComboBox and force DropDownList style

this.comboBox = new ComboBox();

this.comboBox.D ropDownStyle = ComboBoxStyle.D ropDownList;

// Add event handler for notification of when ComboBox loses focus

this.comboBox.L eave += new EventHandler(co mboBox_Leave);

}
// Property to provide access to ComboBox

public ComboBox ComboBox

{

get { return comboBox; }

}
// On edit, add scroll event handler, and display combo box

protected override void Edit(System.Win dows.Forms.Curr encyManager source, int rowNum, System.Drawing. Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)

{

Debug.WriteLine (String.Format( "Edit {0}", rowNum));

base.Edit(sourc e, rowNum, bounds, readOnly, instantText, cellIsVisible);

if (!readOnly && cellIsVisible)

{

// Save current row in the datagrid and currency manager associated with

// the data source for the datagrid

this.iCurrentRo w = rowNum;

this.cm = source;
// Add event handler for datagrid scroll notification

this.DataGridTa bleStyle.DataGr id.Scroll += new EventHandler(Da taGrid_Scroll);

// Site the combo box control within the bounds of the current cell

this.comboBox.P arent = this.TextBox.Pa rent;

Rectangle rect = this.DataGridTa bleStyle.DataGr id.GetCurrentCe llBounds();

this.comboBox.L ocation = rect.Location;

this.comboBox.S ize = new Size(this.TextB ox.Size.Width, this.comboBox.S ize.Height);

// Set combo box selection to given text

this.comboBox.S electedIndex = this.comboBox.F indStringExact( this.TextBox.Te xt);

// Make the ComboBox visible and place on top text box control

this.comboBox.S how();

this.comboBox.B ringToFront();

this.comboBox.F ocus();

}

}

// Given a row, get the value member associated with a row. Use the value

// member to find the associated display member by iterating over bound datasource

protected override object GetColumnValueA tRow(System.Win dows.Forms.Curr encyManager source, int rowNum)

{

Debug.WriteLine (String.Format( "GetColumnValue AtRow {0}", rowNum));

// Given a row number in the datagrid, get the display member

object obj = base.GetColumnV alueAtRow(sourc e, rowNum);
// Iterate through the datasource bound to the ColumnComboBox

// Don't confuse this datasource with the datasource of the associated datagrid

CurrencyManager cm = (CurrencyManage r)

(this.DataGridT ableStyle.DataG rid.BindingCont ext[this.comboBox.D ataSource]);

// Assumes the associated DataGrid is bound to a DataView, or DataTable that

// implements a default DataView

DataView dataview = ((DataView)cm.L ist);
int i;

for (i = 0; i < dataview.Count; i++)

{

if (obj.Equals(dat aview[i][this.comboBox.V alueMember]))

break;

}
if (i < dataview.Count)

return dataview[i][this.comboBox.D isplayMember];
return DBNull.Value;

}

// Given a row and a display member, iterating over bound datasource to find

// the associated value member. Set this value member.

protected override void SetColumnValueA tRow(System.Win dows.Forms.Curr encyManager source, int rowNum, object value)

{

Debug.WriteLine (String.Format( "SetColumnValue AtRow {0} {1}", rowNum, value));

object s = value;

// Iterate through the datasource bound to the ColumnComboBox

// Don't confuse this datasource with the datasource of the associated datagrid

CurrencyManager cm = (CurrencyManage r)

(this.DataGridT ableStyle.DataG rid.BindingCont ext[this.comboBox.D ataSource]);

// Assumes the associated DataGrid is bound to a DataView, or DataTable that

// implements a default DataView

DataView dataview = ((DataView)cm.L ist);

int i;

for (i = 0; i < dataview.Count; i++)

{

if (s.Equals(datav iew[i][this.comboBox.D isplayMember]))

break;

}

// If set item was found return corresponding value, otherwise return DbNull.Value

if(i < dataview.Count)

s = dataview[i][this.comboBox.V alueMember];

else

s = DBNull.Value;
base.SetColumnV alueAtRow(sourc e, rowNum, s);

}

// On datagrid scroll, hide the combobox

private void DataGrid_Scroll (object sender, EventArgs e)

{

Debug.WriteLine ("Scroll");

this.comboBox.H ide();

}

// On combo box losing focus, set the column value, hide the combo box,

// and unregister scroll event handler

private void comboBox_Leave( object sender, EventArgs e)

{

DataRowView rowView = (DataRowView) this.comboBox.S electedItem;

string s = (string) rowView.Row[this.comboBox.D isplayMember];

Debug.WriteLine (String.Format( "Leave: {0} {1}", this.comboBox.T ext, s));

SetColumnValueA tRow(this.cm, this.iCurrentRo w, s);

Invalidate();

this.comboBox.H ide();

this.DataGridTa bleStyle.DataGr id.Scroll -= new EventHandler(Da taGrid_Scroll);

}

}

}

Nov 20 '05 #1
3 6709
Hi Vu Doan Hung,

Tonight you are very lucky - this much code would not normally be converted by anyone here.

I went to http://www.kamalpatel.net/ConvertCSharp2VB.aspx where there is a C# to VB.NET converter program and ran the code
through it. Then I went through it by hand and converted the bits that the program couldn't do. That means that the code below will
now compile.

Whether it will run and do something useful is entirely a different question!! That part is up to you.

Have fun. ;-)

Regards,
Fergus

=============== =============== ==
Imports System
Imports System.Windows. Forms
Imports System.Drawing
Imports System.Data
Imports System.Diagnost ics

Namespace DataGridDemo
' Derive class from DataGridTextBox Column
Public Class DataGridComboBo xColumn
Inherits DataGridTextBox Column

' Hosted ComboBox control
Private _ComboBox As ComboBox
Private cm As CurrencyManager
Private iCurrentRow As Integer

' Constructor - create combobox, register selection change event handler,
' register lose focus event handler
Public Sub New()
Me.cm = Nothing
' Create ComboBox and force DropDownList style
Me._ComboBox = New ComboBox()
Me._ComboBox.Dr opDownStyle = ComboBoxStyle.D ropDownList
' Add event handler for notification of when ComboBox loses focus
AddHandler Me._ComboBox.Le ave, AddressOf comboBox_Leave
End Sub

' Property to provide access to ComboBox
Public ReadOnly Property ComboBox() As ComboBox
Get
Return _ComboBox
End Get
End Property

' On edit, add scroll event handler, and display combo box
Protected Overrides Overloads Sub Edit(ByVal source As System.Windows. Forms.CurrencyM anager, _
ByVal rowNum As Integer, ByVal bounds As System.Drawing. Rectangle, _
ByVal tReadOnly As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
Debug.WriteLine (String.Format( "Edit {0}", rowNum))

MyBase.Edit(sou rce, rowNum, bounds, tReadOnly, instantText, cellIsVisible)
If Not tReadOnly And cellIsVisible Then
' Save current row in the datagrid and currency manager associated with
' the data source for the datagrid
Me.iCurrentRow = rowNum
Me.cm = source

' Add event handler for datagrid scroll notification
AddHandler Me.DataGridTabl eStyle.DataGrid .Scroll, AddressOf DataGrid_Scroll

' Site the combo box control within the bounds of the current cell
Me._ComboBox.Pa rent = Me.TextBox.Pare nt
Dim rect As Rectangle = Me.DataGridTabl eStyle.DataGrid .GetCurrentCell Bounds()
Me._ComboBox.Lo cation = rect.Location
Me._ComboBox.Si ze = New Size(Me.TextBox .Size.Width, Me._ComboBox.Si ze.Height)

' Set combo box selection to given text
Me._ComboBox.Se lectedIndex = Me._ComboBox.Fi ndStringExact(M e.TextBox.Text)

' Make the ComboBox visible and place on top text box control
Me._ComboBox.Sh ow()
Me._ComboBox.Br ingToFront()
Me._ComboBox.Fo cus()
End If
End Sub

' Given a row, get the value member associated with a row. Use the value
' member to find the associated display member by iterating over bound datasource
Protected Overrides Function GetColumnValueA tRow _
(ByVal source As System.Windows. Forms.CurrencyM anager, _
ByVal rowNum As Integer) As Object
Debug.WriteLine (String.Format( "GetColumnValue AtRow {0}", rowNum))

' Given a row number in the datagrid, get the display member
Dim obj As Object = MyBase.GetColum nValueAtRow(sou rce,rowNum)

' Iterate through the datasource bound to the ColumnComboBox
' Don't confuse this datasource with the datasource of the associated datagrid
Dim cm As CurrencyManager = CType((Me.DataG ridTableStyle.D ataGrid.Binding Context _
(Me.comboBox.Da taSource)), CurrencyManager )

' Assumes the associated DataGrid is bound to a DataView, or DataTable that
' implements a default DataView
Dim dataview As DataView = (CType(cm.List, DataView))

Dim i As Integer
For i = 0 To dataview.Count- 1 Step i + 1
If obj.Equals(data view(i)(Me.comb oBox.ValueMembe r)) Then
Exit For
End If
Next

If i < dataview.Count Then
Return dataview(i)(Me. comboBox.Displa yMember)
End If

Return DBNull.Value
End Function

' Given a row and a display member, iterating over bound datasource to find
' the associated value member. Set this value member.
Protected Overrides Sub SetColumnValueA tRow _
(ByVal source As System.Windows. Forms.CurrencyM anager, _
ByVal rowNum As Integer, ByVal value As Object)
Debug.WriteLine (String.Format( "SetColumnValue AtRow {0} {1}", rowNum, value))
Dim s As Object = value

' Iterate through the datasource bound to the ColumnComboBox
' Don't confuse this datasource with the datasource of the associated datagrid
Dim cm As CurrencyManager = CType((Me.DataG ridTableStyle.D ataGrid.Binding Context _
(Me.comboBox.Da taSource)), CurrencyManager )

' Assumes the associated DataGrid is bound to a DataView, or DataTable that
' implements a default DataView
Dim dataview As DataView = (CType(cm.List, DataView))
Dim i As Integer
For i = 0 To dataview.Count- 1 Step i + 1
If s.Equals(datavi ew(i)(Me.comboB ox.DisplayMembe r)) Then
Exit For
End If
Next

' If set item was found return corresponding value, otherwise return DbNull.Value
If i < dataview.Count Then
s = dataview(i)(Me. comboBox.ValueM ember)
Else
s = DBNull.Value
End If

MyBase.SetColum nValueAtRow(sou rce, rowNum, s)
End Sub

' On datagrid scroll, hide the combobox
Private Sub DataGrid_Scroll (ByVal sender As Object, ByVal e As EventArgs)
Debug.WriteLine ("Scroll")
Me.comboBox.Hid e()
End Sub

' On combo box losing focus, set the column value, hide the combo box,
' and unregister scroll event handler
Private Sub comboBox_Leave( ByVal sender As Object, ByVal e As EventArgs)
Dim rowView As DataRowView = CType(Me.comboB ox.SelectedItem , DataRowView)
Dim s As String = CType(rowView.R ow(Me.comboBox. DisplayMember), String)
Debug.WriteLine (String.Format( "Leave: {0} {1}", Me.comboBox.Tex t, s))
SetColumnValueA tRow(Me.cm, Me.iCurrentRow, s)
Invalidate()
Me.comboBox.Hid e()
RemoveHandler Me.DataGridTabl eStyle.DataGrid .Scroll, AddressOf DataGrid_Scroll
End Sub
End Class
End Namespace

'----------------------------------------------------------------
' Converted from C# to VB .NET using CSharpToVBConve rter(1.2).
' Developed by: Kamal Patel (http://www.KamalPatel.net)
' Conversion manually finished by Fergus Cooney.
'----------------------------------------------------------------
Nov 20 '05 #2
* "Vu Doan Hung" <hu**@thainam.n et> scripsit:
I want to change this Class to VB.NET Class, can*you help me ?*


Please don't post in HTML format.

<http://www.remotesoft. com/>
-> "Octopus"

C# -> VB .NET Converters:

<http://www.kamalpatel. net/ConvertCSharp2V B.aspx>
<http://csharpconverter .claritycon.com/Default.aspx>
<http://www.ragingsmurf .com/vbcsharpconvert er.aspx>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Try the Spices.Net (http://9rays.net), this app can convert app to 6 langs
- IL, C#, MC++, VB.Net, J#, Delphi.Net (Octane)

--
Best regards,
Al Ponomarev
9Rays.Net
Nov 20 '05 #4

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

Similar topics

19
7284
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below. Specifically, I have a problem with this portion in the WHERE clause: DATEADD(Day,tblMyEventTableName.ReminderDays, @DateNow) Between CONVERT(smalldatetime,str(DATEPART(Month, @DateNow)+1) + '/' + str(DATEPART(Day, tblMyEventTableName.TaskDateTime)) + '/'...
1
1787
by: Logan X via .NET 247 | last post by:
It's official....Convert blows. I ran a number of tests converting a double to an integer usingboth Convert & CType. I *ASSUMED* that CType would piggy-back ontop of Convert, and that performance would be identical. I was 100% incorrect. The code below produces the results: CType Took: 0.2187528 seconds. Convert Took: 12.187656 seconds.
4
3628
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is of the type the object is instantiated with. In my test program I have Option<std::string> and Option<long>. Here's the code for OptionBase and Option along with a small helper function. In the code are comments describing my problem, look closely...
7
7109
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done without strtol or s/printf function. Thanks, whatluo.
3
10275
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function and there you have it. So I enquired and found the Convert class with it's promising ToInt32 method, great... but it doesn't work. The thing keeps throwing Format Exceptions all over the place. What is the "C#" way to do this??? code int wmin,...
7
29237
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
4
4520
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However it seems this convert is determined by the local settings and comma is indeed used as decimal separator. Is there another way to convert a dotted value to a double variable? Like 1234.5 and not 1234,5
1
3597
by: johnlim20088 | last post by:
Hi, Currently I have 6 web projects located in Visual Source Safe 6.0, as usual, everytime I will open solution file located in my local computer, connected to source safe, then check out/check in some files and work on it. Let say, I want add new page to web project named websiteOrder.sln, i will open websiteOrder.sln in my local computer, connected to websiteOrder.sln located in Visual Source Safe 6.0(source safe located in another...
6
4262
by: Ken Fine | last post by:
This is a basic question. What is the difference between casting and using the Convert.ToXXX methods, from the standpoint of the compiler, in terms of performance, and in other ways? e.g. this.ContentID = (int)ci.Conid; vs. this.ContentID = Convert.ToInt32(ci.Conid); I tend to use the latter form because it seems more descriptive to me, but it would be good to know what's best practice. I'm guessing those methods
0
10766
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8902
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7740
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.