1

Edited Code : the code from before works great but cannot change the textbox.text properties or display them fro each of the controlls added by this loop

any help is appreciated

some sub

    Dim EqLst As String = ""

    Try

        Dim con As New SqlConnection
        Dim myConString As String = getSQLString()
        Dim objcommand As SqlCommand = New SqlCommand

        With objcommand
            .Connection = con
            Dim cmdText As String = "SELECT EquipList from SiteAuditor where client='" & GLClient & "' and market='" & GLMarket & "' and project='" & GLProject & "'"
            .CommandText = cmdText
        End With
        con.ConnectionString = myConString
        con.Open()

        Using readerObj As SqlClient.SqlDataReader = objcommand.ExecuteReader
            'This will loop through all returned records 
            While readerObj.Read

                EqLst = readerObj("EquipList").ToString

                Exit While
            End While
        End Using

        con.Close()

        Dim li As String() = EqLst.Split(",")
        Dim data As New List(Of dataitem)
        For Each name As String In li
            'Form1.DataRepeater1.AddNew()
            data.Add(New dataitem(name))
            Form1.DataRepeater1.CurrentItem.Controls("txtName").Text = name
        Next

        Form1.DataRepeater1.DataSource = data

I guess here is where i need be find out how to add / change my textox names within the datarpeater control anyone have any solutions for me ?

        'For Each name As String In li
        '    Form1.DataRepeater1.CurrentItemIndex(i).text = name
        'Next


    Catch ex As Exception

        Dim thiserror As String = "Error grabDataRepeaterData, " & vbCrLf _
                    & "Email Notifying CLS-Software Developemnt about this error was sent."
        Dim additionalinfo As String = UserLogin & vbCrLf & UserLogin.Replace("CLSGROUP\", "") & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & ex.ToString
        MessageBox.Show(thiserror)
        ErrorEmails(thiserror, additionalinfo)

    End Try


    Return Nothing

end sub

Public Class dataitem
    Public Sub New(text As String)
        Me.text = text
    End Sub
    Public Property text As String
End Class
Pakk
  • 1,299
  • 2
  • 18
  • 36

2 Answers2

2

The DataRepeater has to have its DataSource property set for AddNew to work. It's designed to be data bound.

You can set the dataSource to a list of objects. Then whenever you add to the list, the dataRepeater will automatically show the new items.

Example:

Public Class dataitem
 Public Sub New(text As String)
  Me.text = text
 End Sub
 Public Property text As String
End Class

Public Class Form1
 Public Sub New()
  InitializeComponent()
  Dim data As New List(Of dataitem)
  data.Add(New dataitem("test1"))
  data.Add(New dataitem("test2"))
  DataRepeater1.DataSource = data
 End Sub
End Class
Paul Anderson
  • 1,120
  • 3
  • 11
  • 22
  • I'm sorry would you be able to give me any code examples? - much appreciated – Pakk Apr 30 '13 at 16:37
  • Simply amazing, adding them just as i had asked for - now if you don't mind me asking why can't i set the text attributes to the fields as there being added or must such a thing be done in a loop after there added? – Pakk Apr 30 '13 at 17:28
  • I was working through some similar issues..I just reduced my code to the minimum. To bind the text field you need to add a BindingSource control to the form. Set its datasource, add a project datasource, select the dataitem class. Then set the datasource of the repeater to the bindingSource. then go to your text box properties, you should be able to select the text field as the Text binding. hope that helps. – Paul Anderson Apr 30 '13 at 17:34
  • No chance you got any code for that huh ? - * thanks again if you don't * – Pakk Apr 30 '13 at 18:13
0

Your not declaring the datatype in your for each loop. You need 'as string' after 'name'

For Each name As String In li
        Form1.DataRepeater1.AddNew()
        Form1.DataRepeater1.CurrentItem.Controls("txtName").Text = name
Next
GeorgeK
  • 637
  • 1
  • 8
  • 18
  • Sorry though i c how you could think that , that wasn't the solution im still getting *"Object reference not set to an instance of an object."* error. Thanks for the reply though – Pakk Apr 30 '13 at 16:21