How to Delete a Row From DataGridView Using Bind DataSource

How to Delete a Row From DataGridView Using Bind DataSource thumbnail
.NET exists in part to allow programmers to manipulate data.

Microsoft created the DataGridView class to allow programmers who use its .NET class library to display data in a variety of formats. But the DataGridView class does more than simply display data: It also allows programmers to permit end-users to add, delete and modify information. Before a programmer or end-user can manipulate data, however, they must securely bind the information to the DataGridView. Thankfully, Microsoft has included a means of accomplishing this with its graphical user interface (GUI), as well as in code.

Things You'll Need

  • Visual Studio (2005 or later)
Show More

Instructions

  1. Bind the DataGridView to a Data Source

    • 1

      Open the file that contains the DataGridView object.

    • 2

      Select the smart tag to the right of the DataViewControl, choose "Choose Data Source" and then select the data source of your choice.

    • 3

      Find the specific table or other unit of data that you wish to bind to the DataViewControl by expanding the data source and then selecting the specific target source.

    Delete a Row

    • 4

      Open the code-behind file of the file page that contains the DataGridView.

    • 5

      Remove a data column (which may display as a row in your DataGridView) by calling the DataGridView's ".Remove()" event and feeding it the name of the column in the form of a string:

      'sampleDataGridView.Columns.Remove("RowToRemove");'

    • 6

      Allow a user to delete a row by setting the "AllowUserToDeleteRows" and "IBindingList.AllowRemove" properties to "true":

      'sampleDataGridView.AllowUserToDeleteRows = true;'

      'sampleDataGridView.IBindingList.AllowRemove = true;'

Related Searches:

References

Resources

  • Photo Credit Jupiterimages/Photos.com/Getty Images

Comments

Related Ads

Featured