Microsoft
Software
Hardware
Network
Question : How do I add rows to a datagridview based upon a For Each statement in VS2008?
I am trying to create a datagridview that populates a column with a list of plants and then calculate the number of blooms each plant had for each year that the plant was tracked. This is what is working so far:
Dim records = (From id In d.tblSurveys _
Group By TagNo = id.FinalTag Into Group _
Order By TagNo Ascending _
Select TagNo).ToList
Dim recCount = records.Count
If recCount <= 0 Then
MsgBox("No Data Available.", MsgBoxStyle.Information, "Data Request")
Else
Dim dtable As New DataTable
dtable.Columns.Add("FinalT
ag", GetType(Decimal))
'add the years to the table
For Each y In Me.lbYear.DataSource
dtable.Columns.Add(y, GetType(String))
Next
For Each col In dtable.Columns
Dim dc As New DataGridViewColumn
DGridAllYears.Columns.Add(
dc)
dc.HeaderText = col.ToString
Next
Now I am trying to add rows using the records to this datagridview.
I am able to add the plant list to a datatable and display it through a different datagridview.
For Each rec In records
Dim datarow As DataRow = dtable.NewRow
datarow.Item(0) = rec.Value
dtable.Rows.Add(datarow)
Next
But I can't seem to convert this method to a datagridview...
Any help or suggestions would be appreciated!
Thanks.
Answer : How do I add rows to a datagridview based upon a For Each statement in VS2008?
You might have two different types of line breaks.
Try this
Sub zap()
ActiveSheet.[A:A].Replace Chr(13) & Chr(10), " "
ActiveSheet.[A:A].Replace Chr(10), " "
ActiveSheet.[A:A].Replace Chr(13), " "
End Sub
Random Solutions
Printing issues: Printing to a Microsoft Terminal server 2003
site permissions not working for restored sharepoint site
VBA to update field values on a table during a loop
Cannot connect to the virtual machine in Server 2008 after Hyper v set up
avoid the reserved space
pattern matching regular expression
How to merge two List?
ORDER BY items must appear in the select list if the statement contains a UNION operator.
SQL Dates
Copying a sheet from one file to another without opening either in Excel