ruca wrote:
hi,
How can I fill some DataTable by clicking in cells of a DataGrid control?
NOTE: I don't want to select a entire row, ok? I must select only one or
more cells...
I have a DataGrid that have some data that I must select what I want and
then by clicking in a Button it will create some records in DataBase.
So I want to construct a DataTable by clicking in DataGrid, for then allows
me to cover this DataTable and create the records in DB.
The example below is used to make it so no column can be selected but
selects the entire row instead. Add it to your datagridtablestyle.
Then you will need to capture the click event in the datagrid (probably
should just be capture the row change instead) and do a datagridhittest
on it.
Hope that helps
Chris
FullDisclosure: This was used from some website... No idea who
Public Class DataGridNoActiveCellColumn
Inherits DataGridTextBoxColumn
Private SelectedRow As Integer = -1
Protected Overloads Overrides Sub Edit(ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal
bounds As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal
instantText As String, ByVal cellIsVisible As Boolean)
'make sure previous selection is valid
If SelectedRow > -1 And SelectedRow < source.List.Count + 1 Then
Me.DataGridTableStyle.DataGrid.UnSelect(SelectedRo w)
End If
SelectedRow = rowNum
Me.DataGridTableStyle.DataGrid.Select(SelectedRow)
End Sub
End Class