Inquiridor
DataGridView e DataGrid

Pergunta
-
Pessoal tenho um dataGrid formatado que peguei em um dos projetos que faço, mas com a evolução quero usar o DataGridView mas da seguinte maneira
Code SnippetPublic
Class siagDataGrid Inherits System.Windows.Forms.DataGrid Private Const WM_SETCURSOR As Integer = 32 Dim intRow As Integer Dim intColunaHand As Integer = -1 Property ColunaHand() As Integer Get Return intColunaHand End Get Set(ByVal Value As Integer)intColunaHand = Value
End Set End Property Public Event RowChanged(ByVal sender As Object, ByVal e As System.EventArgs) Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean If msg.WParam.ToInt32() = CInt(Keys.Enter) ThenSendKeys.Send(
"{Tab}") Return True End If Return MyBase.ProcessCmdKey(msg, keyData) End Function Protected Overloads Overrides Sub OnCurrentCellChanged(ByVal e As System.EventArgs) If intRow <> MyBase.CurrentCell.RowNumber Then RaiseEvent RowChanged(Me, e)intRow =
MyBase.CurrentCell.RowNumber End If MyBase.OnCurrentCellChanged(e) End Sub Protected Overrides Sub OnEnter(ByVal e As System.EventArgs) RaiseEvent RowChanged(Me, e) End Sub Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg <> WM_SETCURSOR Or intColunaHand = -1 Then MyBase.WndProc(m) Else 'se a for a coluna que contem o icone Dim pt As Point = Me.PointToClient(Control.MousePosition) Dim hti As DataGrid.HitTestInfo = Me.HitTest(pt.X, pt.Y) If hti.Column = intColunaHand ThenCursor.Current = System.Windows.Forms.Cursors.Hand
'if not, call the baseclass Else MyBase.WndProc(m) End If End If End Sub End Class 'MyDataGridE eu o chamo no form na parte que fica Form1.Designer.vb assim:
Code SnippetPrivate
Sub InitializeComponent() Me.grd = New ncCorp.ctr.siagDataGrid CType(Me.grd, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'grd ' Me.grd.CaptionVisible = False Me.grd.ColunaHand = -1 Me.grd.DataMember = "" Me.grd.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!) Me.grd.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.grd.Location = New System.Drawing.Point(12, 12) Me.grd.Name = "grd" Me.grd.ReadOnly = True Me.grd.RowHeaderWidth = 20 Me.grd.Size = New System.Drawing.Size(268, 175) Me.grd.TabIndex = 153 ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.Add(Me.grd) Me.Name = "Form1" Me.Text = "Form1" CType(Me.grd, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub Friend WithEvents grd As ncCorp.ctr.siagDataGridE na chamada para preenchimento de código eh da seguinte maneira, onde eu trago os dados para o DataGrid:
Code SnippetPrivate Sub ConfigDataGrid()
Dim myGridStyle As DataGridTableStyle = New DataGridTableStylemyGridStyle.MappingName =
"Cliente"myGridStyle.ColumnHeadersVisible =
TruemyGridStyle.AllowSorting =
FalsemyGridStyle.RowHeadersVisible =
True Dim col1 As DataGridColumnStyle = New DataGridColorTextBoxColumncol1.MappingName =
"idptcestudante"col1.ReadOnly =
Truecol1.HeaderText =
"Código"col1.Width = 50
col1.NullText =
"" Dim col11 As DataGridColumnStyle = New DataGridColorTextBoxColumncol11.MappingName =
"numerodes"col11.ReadOnly =
Truecol11.HeaderText =
"Número"col11.Width = 60
col11.NullText =
"" Dim col2 As DataGridColumnStyle = New DataGridColorTextBoxColumncol2.MappingName =
"nomeestudante"col2.ReadOnly =
Truecol2.HeaderText =
"Nome"col2.Width = 210
col2.NullText =
"" Dim col3 As DataGridColumnStyle = New DataGridColorTextBoxColumncol3.MappingName =
"nome"col3.ReadOnly =
Truecol3.HeaderText =
"Cliente"col3.Width = 110
col3.NullText =
""myGridStyle.GridColumnStyles.Add(col1)
myGridStyle.GridColumnStyles.Add(col2)
myGridStyle.GridColumnStyles.Add(col3)
grd.TableStyles.Clear()
grd.TableStyles.Add(myGridStyle)
grd.ReadOnly =
Truecol1 =
Nothing : col2 = Nothing End Sub