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);
}
}
}