Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing row from datagrid

Status
Not open for further replies.

sp76

Programmer
Jul 1, 2003
59
AU

Please Help!!!

How can i remove a particular row from the DataGrid???
 
assuming that u ( thread initiator ) have populated using database. Then u have to run and delete against database and reload the grid to reflect the database changes.


Cracky -= Developer/DBA =-
visit :
 

You can accomplish it without reloading the grid as well, using DataView and Currency Manager object. Try the following code, make appropriate changes

'Declare class level variable.
Dim objDV As DataView
Dim objCM As CurrencyManager

Private Sub PopulateDataGrid()
Dim selectString As String
Dim objDA As OleDbDataAdapter
Dim objDS As New DataSet()

Try
'Initialize the SQL string.
selectString = "Your SQL SELECT statement"

'Initialize the OleDbDataAdapter object and fill DataSet.
objDA = New OleDbDataAdapter(selectString, MyConnection)
objDA.Fill(objDS, "yourTableName")

'Set the DataView object to the DataSet object.
myDV = New DataView(objDS.Tables("yourTableName"))

'Set our CurrencyManager object to the DataView object.
objCM = CType(Me.BindingContext(myDV), CurrencyManager)

myDataGrid.DataSource = myDV

Catch Excep As System.Exception
MessageBox.Show(Excep.Message, "Prospect Management System (srcPros)", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub

Private Sub onDeleteClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
If MessageBox.Show("Are you sure to delete this record?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.Yes Then
'Call your delete procedure
DeleteProspect()

'Remove deleted row from the DataGrid.
myDV.Delete(myCurrencyManager.Position)
End If
End Sub



Email: pankajmsm@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top