
Translation Problems (C# to VB)
Here are a couple of web links that offer C# to VB translators. They are not
perfect, but probably can handle these snippets.
http://www.aspalliance.com/aldotnet/examples/translate.aspx
http://www.kamalpatel.net/ConvertCSharp2VB.aspx
Here is a translation of the snippets you showed.
Public Function GetSelectedRows(ByVal datagrid1 As DataGrid) As
System.Collections.ArrayList
Dim al As New System.Collections.ArrayList()
Dim i As Integer
' line assume's datasource is dataset - if datasource is
datatable 2nd option
' While i < CType(dataGrid1.DataSource,
DataSet).Tables(0).Rows.Count 'option 1
While i < CType(datagrid1.DataSource, DataTable).Rows.Count
'option 2
If datagrid1.IsSelected(i) Then
al.Add(i)
End If
i = i + 1
End While
Return al
End Function 'GetSelectedRows
Private Sub button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim s As String = "Selected rows:"
Dim o As Object
For Each o In GetSelectedRows(dataGrid1)
s += " " + o.ToString()
Next o
MessageBox.Show(s)
End Sub 'button1_Click
End Class
======================
Clay Burch
Syncfusion, Inc.
Visit www.syncfusion.com for .NET Essentials
Quote:
> Hi,
> On the internet I found the solution to a problem (that's a good thing),
but
> it is written in C# (that a bad thing).
> I tried everything I could imagine but I can't seem to translate it to VB
so
> it works...
> Specialy the for line makes me go crazy ;-)
> Any ideas???
> Thanks in advance,
> Dieter
> ------------The code...------------
> public ArrayList GetSelectedRows(DataGrid datagrid1)
> {
> ArrayList al = new ArrayList();
> for(int i = 0; i <
((DataSet)dataGrid1.DataSource).Tables[0].Rows.Count;
Quote:
> ++i)
> {
> if(datagrid1.IsSelected(i))
> al.Add(i);
> }
> return al;
> }
> private void button1_Click(object sender, System.EventArgs e)
> {
> string s = "Selected rows:";
> foreach(object o in GetSelectedRows(dataGrid1))
> {
> s+=""+o.ToString();
> }
> MessageBox.Show(s);
> }