Vb.net. How to associate a dataset with a DataRepeater?

I am looking for a vb.net example, how to associate a dataset / datatable with a data relay and bind data elements to columns of a dataset / datatable? Thanks

+3
source share
2 answers

At first I thought you needed a web repeater, but from your comments, I realized that you mean Microsoft.VisualBasic.PowerPacks.DataRepeater.

I need more information from you to give the most useful sample code (see below).

DataRepeater:
1) Power Pack 3 Visual Basic
2) VB.net Winforms DataRepeater
3) "" > " "
4) 5) " " "" > "ShowDataSources"
6) Dataset , ""
7) DataRepeater ( ). DataRepeater. .
8) Datset, DataRepeater . .
.

me.DataSet1.Tables(0).Columns.Add(New String() {"John", "Doe", "Accountant"}  

myDataAdapter.Fill(me.DataSet1.Tables(0)) 

?


:

, , , DataRepeater , / , DataRepeater, . , , , DataReader .

/ DataRepeater , , . Form3 DataRepeater DataRepeater1 Button1...

Public Class Form3

    ''Set up demo DataSet/DataTable
    Const FRUIT_COL As String = "Fruit"
    Const COLOR_COL As String = "Color"
    MyDataSet = New DataSet
    MyDataSet.Tables.Add("MyTable")
    With MyDataSet.Tables(0)
        .Columns.Add(FRUIT_COL, GetType(System.String))
        .Columns.Add(COLOR_COL, GetType(System.String))
    End With

    ''Populate the DataTable with sample data. You would be loading from SQL
    With MyDataSet.Tables(0)
        .Rows.Add(New String() {"Apple", "Red"})
        .Rows.Add(New String() {"Orange", "Orange"})
        .Rows.Add(New String() {"Banana", "Yellow"})
    End With

    ''These objects would normally be created automatically if you added DataTable to DataRepeater at design-time
    FruitLabel = New Label
    FruitTextBox = New TextBox
    ColorLabel = New Label
    ColorTextBox = New TextBox
    With FruitLabel
        .AutoSize = True
        .Location = New Point(10, 20)
        .Name = "FruitLabel"
        .Text = FRUIT_COL
    End With
    With ColorLabel
        .AutoSize = True
        .Location = New Point(10, 60)
        .Name = "FruitLabel"
        .Text = FRUIT_COL
    End With
    With FruitTextBox
        .Location = New Point(50, 20)
        .Size = New Size(60, 15)
        .DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.MyDataSet.Tables(0), FRUIT_COL, True))
    End With
    With ColorTextBox
        .Size = New Size(60, 15)
        .Location = New Point(50, 60)
        .DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.MyDataSet.Tables(0), COLOR_COL, True))
    End With

    ''Add the controls that will be displayed for each row in DataTable
    With DataRepeater1
        .ItemTemplate.Controls.Add(FruitLabel)
        .ItemTemplate.Controls.Add(FruitTextBox)
        .ItemTemplate.Controls.Add(ColorLabel)
        .ItemTemplate.Controls.Add(ColorTextBox)
    End With

    ''Run-time population of DataRepeater from your DataTable
    DataRepeater1.DataSource = MyDataSet
    DataRepeater1.DataMember = MyDataSet.Tables(0).TableName

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Example of how you can add additional rows with form elements
    With MyDataSet.Tables(0)
        .Rows.Add(New String() {"Grapes", "Green"})
    End With
End Sub
End Class

, , , :)
DataSet , .

, DataRepeater:

. "" , . const "Test", .

[ControlName].DataBindings.Add(New System.Windows.Forms.Binding("Text", [DataTable], [Column Name], True))
+3
Dim data As DataSet
DataRepeater1.DataSource = data
DataRepeater1.DataBind()
+1

Source: https://habr.com/ru/post/1731974/


All Articles