DataGrid

V

Vince

I load a datagrid with the following routine:
Private Sub loadDataGrid()
Dim strSql As String = Globals.RECV_TRANS
Dim cn As SqlCeConnection
cn = New SqlCeConnection( connString )
Dim sqlDA As SqlCeDataAdapter
Dim sqlDS As New DataSet
sqlDA = New SqlCeDataAdapter(strSql, cn)
sqlDA.Fill(sqlDS, "Receipts")
recvGrid.DataSource = sqlDS.Tables("Receipts")
setColumnNames()
recvGrid.Refresh()
End Sub

Then I select a row, and click a delete button on my
form. I go ahead and do the delete from my SQL CE
database. Now I want to reload the datagrid with the new
data. But I can't call the above function, I always get
an Argument Exception.

My Delete routine:
Private Sub Button1_Click_1(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles btnDelete.Click

If (MsgBox("Delete Record?", MsgBoxStyle.YesNo)
= MsgBoxResult.No) Then
Exit Sub
End If

If (DeleteRow() = False) Then
MsgBox("Delete Failed")
Exit Sub
End If

loadDataGrid()

End Sub

What am I doing wrong?

Thanks

-Vince
 
M

Michel Renaud

The datagrid seems to freak out when you delete something
from its datasource (I've tried several alternatives.) I
ended up setting the datasource to nothing before
deletion, then resetting it afterwards. Of course I had
to keep the current row in memory and reset it as well,
and I also made sure the display wasn't updated until
after I reset the datasource, so the user doesn't see
anything out of the ordinary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top