add data to a datagrid when table is empty

  • 13 years ago

    Hi, I am trying to add data programatically to a datagrid, it works okay unless the table is empty.

    "row is not valid". is there an add new row or something?

    Here is what meagre code I have (just testing how it works.)

    Any help will be much appreciated.

    The datagrid's data source is an ADODC control.

    Private Sub Command1_Click()
    MsgBox DataGrid1.ApproxCount
    DataGrid1.Text = "this won't work if there is no data already in table"
    DataGrid1.Row = DataGrid1.Row + 1

    End Sub

    Private Sub DataGrid1_Click()
    MsgBox DataGrid1.Row

    End Sub

    Private Sub Form_Load()
    Adodc1.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\products.mdb"
    Adodc1.RecordSource = "select * from tblReport"

    Set DataGrid1.DataSource = Adodc1
    'MsgBox DataGrid1.Row
    'MsgBox DataGrid1.ApproxCount

    DataGrid1.RecordSelectors = True

    End Sub

  • 13 years ago

    I seem to be answering a lot of my own questions lately. Wink [;)]

    I got rid of the datagrid and added data to my records with the following code: (Blue code at end)

    Private Sub cmdCalculate_Click()
    For Index = 1 To Text1.Count - 1
    Text1(Index).Locked = True
    Next Index

    y = 0
    z = 0
    For y = 1 To txtOutputFormula.Count - 1
        For z = 1 To Text1.Count - 1
        startpos = InStr(1, txtOutputFormula(y).Text, "[" & Text1(z).Tag & "]")
        If startpos > 0 Then
         tempstr = Replace(txtOutputFormula(y).Text, "[" & Text1(z).Tag & "]", Text1(z).Text)
         'MsgBox tempstr
         txtOutputFormula(y).Text = tempstr
        End If
        ' MsgBox "[" & Text1(z).Tag & "]"
        Next z
    Next y

    For p = 1 To txtResult.Count - 1
    txtResult(p).Text = ScriptControl1.Eval(txtOutputFormula(p))
    txtResult(p).Visible = True

    Next p

    For Index = 1 To Text1.Count - 1
    Text1(Index).Enabled = False
    Next Index
    cmdCalculate.Enabled = False

    Set db = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\products.mdb")
    Set rstrecordset = db.OpenRecordset("SELECT * FROM tblReport", dbOpenDynaset)

    For loopy = 1 To txtOutputNumberOfCuts.Count - 1
    rstrecordset.Fields(0) = txtOutputName(loopy)
    rstrecordset.Fields(1) = txtOutputNumberOfCuts(loopy)
    rstrecordset.Fields(2) = txtResult(loopy)

    Next loopy

    Set rstrecordset = Nothing

    Set db = Nothing

    End Sub


Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Walking on water and developing software from a specification are easy if both are frozen.” - Edward V Berard