how do I add data with the bottom input row in a datagrid?

kilobyte

Newcomer
Joined
Sep 10, 2003
Messages
8
Ok, I have another question ready...

I'm still doing a windows app with a datagrid in it. I want the user to be able to add rows to the dataset by just inputting data in the empty bottom row, and then move focus to a different row. This is is how it works in eg. Enterprise Manager for SQL Server.

I was planning on doing this by going through the Row list of the datasource (it's a DataView) in the CurrentCellChanged event, and then adding a row to the underlying datatable if there was any data in the 'input row'.

My problem is that when there is no data in the bottom row it shows up fine in the Row list of the dataview during runtime. But if I enter some data into the bottom row, the row somehow disappears from the Row list!

Does anybody know why this happens?

Thanks
MNJ
 
No, I just checked and that's set to true. And the filter is set to CurrentRows so it shouldn't be filtered either.

I made a dialog now to circumvent this, but I would prefer using the bottom row if I knew how to...
 
Code:
 Dim DS As DataSet
        Dim Table As DataTable
        Dim R As System.Data.DataRow
        Dim DV As DataView
        Table = New DataTable("My Table")

        Table.BeginLoadData()
        With Table.Columns.Add("String Column", GetType(String))
            .DefaultValue = ""
            .ReadOnly = False ' Optional... had it to true
        End With
        With Table.Columns.Add("Integer Column", GetType(Integer))
            .DefaultValue = 0
            .ReadOnly = False
        End With
        Dim i As Integer
        For i = 1 To 10
            R = Table.NewRow
            R(0) = "Bla bla bla"
            R(1) = i
            Table.Rows.Add(R)
        Next
        Table.EndLoadData()

        DV = New DataView(Table)
        DataGrid1.DataSource = DV

This works....
 
Funny thing is that some time ago i was searching for how to remove that append row in the end.
Oh and if u are displaying the results of a querry that cannot be updated directly from its source, the datagrid will hide the append row. This applies to any other collection of records that cannot be updated for some reason. Dont ask me which querries cannot be updated because i dont like to grant direct access to the database for validation purposes etc. so i dont bind controls directly to the source.
 
Back
Top