Frage

I have a form with a datagridview containing entries for an invoice. I have created a separate form that will contain the entries from the datagridview in labels. Unfortunately, I am having trouble finding out how to generate a table of labels with each label holding the value of the corresponding entry in the datagridview. I am wondering if it is possible to do this with a for next loop based on the number of rows in the datagridview. Thanks in advance for any guidance in this!

War es hilfreich?

Lösung

Dim lbl As New Label
With lbl
   .Text = txtCaption    ' value you want it to display from dgv.dr
   .Top = 
   .Left = 
   .Name =
   .Size =
End With

I dont know what you mean by a table of labels, so lets say you want to add them to a panel there just for them:

pnlLabels.Controls.Add(lbl)

Make that a Sub and call it from the loop processing the rows in the datagridview, passing the relevant value for its caption. Something like this:

CreateLabel(ndx as Integer, txtCaption as String)

You will need an index or counter of how many made so that some properties like .Top can be offset accordingly.

EDIT

I have no idea what your dgv or data etc looks like, but your loop would be SOMETHING like this:

pnlLabels.Controls.Clear             ' might want to remove any old ones

Dim Caption as String = ""
Dim ndx As Integer = 0
For Each dr As DataGridViewRow in dgv.rows
     Caption = dr.Cells(X)        ' or where the data is

     CreateLabel(ndx, Caption)
     ndx += 1
Next
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top