LorneBackler
asked on
looping through datagrid on windows form/
Hi experts!
I have created datagrid on windows form and i displayed records from database.
The datagrid has about 50 records in it,
How can i loop throgh datagrid and print all the records?
Thanks
I have created datagrid on windows form and i displayed records from database.
The datagrid has about 50 records in it,
How can i loop throgh datagrid and print all the records?
Thanks
instead of
Dim cm As CurrencyManager = Me.BindingContext(dg.DataS ource, dg.DataMember)
Dim dv As DataView = CType(cm.List, DataView)
if you have a DataSet then you can directly create the dataview from the dataset
Dim cm As CurrencyManager = Me.BindingContext(dg.DataS
Dim dv As DataView = CType(cm.List, DataView)
if you have a DataSet then you can directly create the dataview from the dataset
If your datagrid's datasource is a datatable:
Dim s As String
Dim i As Integer
Dim j As Integer
For i = 0 To myDataSet.Tables("myTable" ).Rows.Cou nt - 1
For j = 0 To 5 ' Suppose you have 6 columns in datagrid
s &= DataGrid1(i, j)
If j < 5 Then ' Last column doesn't need " | " to the right of it
s &= " | "
End If
Next
If i < myDataSet.Tables("myTable" ).Rows.Cou nt - 1 Then ' Last row doesn't need line carriage
s &= vbCrlf
End If
Next
Console.WriteLine(s)
Dim s As String
Dim i As Integer
Dim j As Integer
For i = 0 To myDataSet.Tables("myTable"
For j = 0 To 5 ' Suppose you have 6 columns in datagrid
s &= DataGrid1(i, j)
If j < 5 Then ' Last column doesn't need " | " to the right of it
s &= " | "
End If
Next
If i < myDataSet.Tables("myTable"
s &= vbCrlf
End If
Next
Console.WriteLine(s)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Public Function GetSelectedRows(ByVal dg As DataGrid)
Dim cm As CurrencyManager = Me.BindingContext(dg.DataS
Dim dv As DataView = CType(cm.List, DataView)
Dim i As Integer
For i = 0 To dv.Count - 1
'write code to print your coulmns
Next
End Function