473,398 Members | 2,335 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,398 software developers and data experts.

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.Diagnostics;

namespace DataGridDemo

{

// Derive class from DataGridTextBoxColumn

public class DataGridComboBoxColumn : DataGridTextBoxColumn

{

// 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 DataGridComboBoxColumn()

{

this.cm = null;

// Create ComboBox and force DropDownList style

this.comboBox = new ComboBox();

this.comboBox.DropDownStyle = ComboBoxStyle.DropDownList;

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

this.comboBox.Leave += new EventHandler(comboBox_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.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)

{

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

base.Edit(source, 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.iCurrentRow = rowNum;

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

this.DataGridTableStyle.DataGrid.Scroll += new EventHandler(DataGrid_Scroll);

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

this.comboBox.Parent = this.TextBox.Parent;

Rectangle rect = this.DataGridTableStyle.DataGrid.GetCurrentCellBou nds();

this.comboBox.Location = rect.Location;

this.comboBox.Size = new Size(this.TextBox.Size.Width, this.comboBox.Size.Height);

// Set combo box selection to given text

this.comboBox.SelectedIndex = this.comboBox.FindStringExact(this.TextBox.Text);

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

this.comboBox.Show();

this.comboBox.BringToFront();

this.comboBox.Focus();

}

}

// 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 GetColumnValueAtRow(System.Windows.Forms.CurrencyM anager source, int rowNum)

{

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

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

object obj = base.GetColumnValueAtRow(source, rowNum);
// Iterate through the datasource bound to the ColumnComboBox

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

CurrencyManager cm = (CurrencyManager)

(this.DataGridTableStyle.DataGrid.BindingContext[this.comboBox.DataSource]);

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

// implements a default DataView

DataView dataview = ((DataView)cm.List);
int i;

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

{

if (obj.Equals(dataview[i][this.comboBox.ValueMember]))

break;

}
if (i < dataview.Count)

return dataview[i][this.comboBox.DisplayMember];
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 SetColumnValueAtRow(System.Windows.Forms.CurrencyM anager source, int rowNum, object value)

{

Debug.WriteLine(String.Format("SetColumnValueAtRow {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 = (CurrencyManager)

(this.DataGridTableStyle.DataGrid.BindingContext[this.comboBox.DataSource]);

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

// implements a default DataView

DataView dataview = ((DataView)cm.List);

int i;

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

{

if (s.Equals(dataview[i][this.comboBox.DisplayMember]))

break;

}

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

if(i < dataview.Count)

s = dataview[i][this.comboBox.ValueMember];

else

s = DBNull.Value;
base.SetColumnValueAtRow(source, rowNum, s);

}

// On datagrid scroll, hide the combobox

private void DataGrid_Scroll(object sender, EventArgs e)

{

Debug.WriteLine("Scroll");

this.comboBox.Hide();

}

// 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.SelectedItem;

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

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

SetColumnValueAtRow(this.cm, this.iCurrentRow, s);

Invalidate();

this.comboBox.Hide();

this.DataGridTableStyle.DataGrid.Scroll -= new EventHandler(DataGrid_Scroll);

}

}

}

Nov 20 '05 #1
3 6691
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.Diagnostics

Namespace DataGridDemo
' Derive class from DataGridTextBoxColumn
Public Class DataGridComboBoxColumn
Inherits DataGridTextBoxColumn

' 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.DropDownStyle = ComboBoxStyle.DropDownList
' Add event handler for notification of when ComboBox loses focus
AddHandler Me._ComboBox.Leave, 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.CurrencyManager, _
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(source, 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.DataGridTableStyle.DataGrid.Scroll, AddressOf DataGrid_Scroll

' Site the combo box control within the bounds of the current cell
Me._ComboBox.Parent = Me.TextBox.Parent
Dim rect As Rectangle = Me.DataGridTableStyle.DataGrid.GetCurrentCellBound s()
Me._ComboBox.Location = rect.Location
Me._ComboBox.Size = New Size(Me.TextBox.Size.Width, Me._ComboBox.Size.Height)

' Set combo box selection to given text
Me._ComboBox.SelectedIndex = Me._ComboBox.FindStringExact(Me.TextBox.Text)

' Make the ComboBox visible and place on top text box control
Me._ComboBox.Show()
Me._ComboBox.BringToFront()
Me._ComboBox.Focus()
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 GetColumnValueAtRow _
(ByVal source As System.Windows.Forms.CurrencyManager, _
ByVal rowNum As Integer) As Object
Debug.WriteLine(String.Format("GetColumnValueAtRow {0}", rowNum))

' Given a row number in the datagrid, get the display member
Dim obj As Object = MyBase.GetColumnValueAtRow(source,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.DataGridTableStyle.DataGrid.BindingConte xt _
(Me.comboBox.DataSource)), 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(dataview(i)(Me.comboBox.ValueMember)) Then
Exit For
End If
Next

If i < dataview.Count Then
Return dataview(i)(Me.comboBox.DisplayMember)
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 SetColumnValueAtRow _
(ByVal source As System.Windows.Forms.CurrencyManager, _
ByVal rowNum As Integer, ByVal value As Object)
Debug.WriteLine(String.Format("SetColumnValueAtRow {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.DataGridTableStyle.DataGrid.BindingConte xt _
(Me.comboBox.DataSource)), 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(dataview(i)(Me.comboBox.DisplayMember)) 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.ValueMember)
Else
s = DBNull.Value
End If

MyBase.SetColumnValueAtRow(source, 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.Hide()
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.comboBox.SelectedItem, DataRowView)
Dim s As String = CType(rowView.Row(Me.comboBox.DisplayMember), String)
Debug.WriteLine(String.Format("Leave: {0} {1}", Me.comboBox.Text, s))
SetColumnValueAtRow(Me.cm, Me.iCurrentRow, s)
Invalidate()
Me.comboBox.Hide()
RemoveHandler Me.DataGridTableStyle.DataGrid.Scroll, AddressOf DataGrid_Scroll
End Sub
End Class
End Namespace

'----------------------------------------------------------------
' Converted from C# to VB .NET using CSharpToVBConverter(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.net> 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/ConvertCSharp2VB.aspx>
<http://csharpconverter.claritycon.com/Default.aspx>
<http://www.ragingsmurf.com/vbcsharpconverter.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
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....
1
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...
4
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...
7
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...
3
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...
7
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
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...
1
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...
6
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. ...
0
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...
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
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
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,...
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
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
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...
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,...
0
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...

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.