Rich G

I have a DataGridView that I am using as a universial grid for several tables. In it's implementation in the form load event I use the following code:

If Not myTableName = "" Then

Me.Text = Me.myTableName & " Editor"

Dim strSQL As String = "SELECT * FROM " & myTableName & ";"

myDataAdapter = GetDataAdapter(strSQL)

myDataAdapter.Fill(myDataTable)

dgView1.DataSource = New DataView(myDataTable)

dgView1.AllowUserToDeleteRows = True

End If

Public Function GetDataAdapter(ByVal strSQL As String) As Common.DbDataAdapter

Dim strConn As String = _

Global.BHRmain.My.MySettings.Default.BHRdataViaExpress

Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection(strConn)

Dim adapter As Common.DbDataAdapter = New SqlClient.SqlDataAdapter(strSQL, connection)

Dim comBuilder As SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder(adapter)

Return adapter

End Function

In the help system it says that for me to be able to delete a row from the grid, I need to set "IBindingList.AllowRemove". I haven't a clue as to what this means. I cannot find this reference anywhere in the objects I have.

Is there somewhere I can tell this thing that it is OK to delete a row.

Thanks, Rich




Re: Visual Basic General Having a problem deleting a row in a DataGridView

cybertaz69

Are you getting the error when you delete the row from the DGV or when you run the adapter.update






Re: Visual Basic General Having a problem deleting a row in a DataGridView

Rich G

Hi,

The message I'm getting is:

Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.

I get this when I click a Continue button. Under the Continue button is:

myDataAdapter.Update(myDataTable)

I've noticed that when I click on the row selector that the row is not really selected. It highlights the columns 1 through the end, but column 0 has only the text highlighted. If I press the Delete Key in an attempt to delete the row, only the text in column 0 is deleted. This may be the root cause of the problem. I cannot select the whole row.

The Selection Mode for the grid is RowHeaderSelect.

Rich






Re: Visual Basic General Having a problem deleting a row in a DataGridView

cybertaz69

Rich G wrote:

I've noticed that when I click on the row selector that the row is not really selected. It highlights the columns 1 through the end, but column 0 has only the text highlighted. If I press the Delete Key in an attempt to delete the row, only the text in column 0 is deleted.

Thats odd behavior for a DGV.... Have you change any DGV display setting

To the root of your issue.... Your query doesn't include the tables key. That the column that has the unquie value different from all other rows... Rebuild your dataset table and include the key columns. When you display the DGV it will have the column but you can go into the column collection and make them hiden inside the DGV...






Re: Visual Basic General Having a problem deleting a row in a DataGridView

Rich G

I noticed in another form I have setup that is supposed to be for view onlly, that the row will select.

The line I am using to make it for view only is "dgView1.ReadOnly = True"

So I set my universal grid to ReadOnly and it allowed me to select a row. Then I made sure that the underlying data had a Primary Key set in the SQL Express tool. With these conditions I am able to select and delete a row, but I am not able to edit the contents of a row.

I don't think I changed anything on the grid setup. I usually don't. But with that in mind, I'm going to setup a test in another project and make sure I use very standard grid settings.






Re: Visual Basic General Having a problem deleting a row in a DataGridView

Rich G

One of the properties was changed; EditMode was not set to the default EditOnKeystrokeOrF2

it was set to EditOnEnter. If you double click a property the selections change. That may be

how I set it to something other than the default.

Thanks for your help Taz