VB.NET - Edit a DataGrid



Allows you to edit the cells in a DataGrid

'Assembly: System.Data.dll
'Assembly: System.Windows.Forms.dll
'Assembly: System.Windows.Forms.DataGrid.dll

'Namespace: Microsoft.VisualBasic
'Namespace: System.Windows.Forms
'Namespace: System.Data
'Namespace: System

'Dim datagrid AS DataGrid
'Dim button AS Button

Private Sub dataGrid_CurrentCellChanged(ByVal sender As Object, ByVal e As EventArgs) _
    Handles datagrid.CurrentCellChanged

    Dim currentCell As DataGridCell
    Dim currentCellData As String

    ' Get the current cell.
    currentCell = datagrid.CurrentCell

    ' Get the current cell's data.
    currentCellData = CStr(datagrid(currentCell.RowNumber, currentCell.ColumnNumber))

    ' interact with currentCellData

End Sub

Private Sub buttonSetCurrentCell_Click(ByVal o As Object, ByVal e As EventArgs) _
    Handles button.Click

    Dim currentCell As DataGridCell
    Dim currentCellData As String

    ' Get the text to put into the current cell.
    currentCellData = "currentCellData"

    ' Get the current cell.
    currentCell = datagrid.CurrentCell

    ' Set the current cell's data.
    datagrid(currentCell.RowNumber, currentCell.ColumnNumber) = currentCellData
End Sub

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.