Seleccion de fila

10/07/2004 - 04:35 por Traveceras | Informe spam
Mis estimados ..

recuerdo haberles escrito esta pregunta antes.. y segun
yo. ya habia dado con solucion.. pero no fue asi..

por lo tanto espero y me puedan ayudar..

necesito seleccionar una fila completa del datagrid. cada
q me muevo en ella con las teclas .. no con el mouse..

lo q he desarrollado hasta ahorita es tomar el evento
datagrid1.currentcell_changed y poner lo siguiente

filaN = DataGrid1.CurrentCell.RowNumber
DataGrid1.Select(filaN)

si me selecciona la linea pero cuando empiezo a navegar
con las flechas del teclado. me pone el cursor como si
fuera a escribir algo..

lo q yo necesito exactamente es seleccionar toda la fila
pero evitar me aparezca el cursor de edicion en cada
celda..

si alguien tiene una sugerencia de antemano.. muchas
gracias..

Carlos Traveceras
Gdl jalisco Mexico
 

Leer las respuestas

#1 Eduardo A. Morcillo [MS MVP VB]
10/07/2004 - 07:12 | Informe spam
Puedes crear tu propio estilo de columna (una clase derivada de
DataGridColumnStyle) que no permita edicion y crear un tablestyle usando ese
estilo de columna. Este es un ejemplo:

Public Class DataGridDisplayOnlyColumn
Inherits DataGridColumnStyle

Protected Overrides Sub Abort(ByVal rowNum As Integer)
End Sub

Protected Overrides Function Commit(ByVal dataSource As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Boolean
Return True
End Function

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)
End Sub

Protected Overrides Function GetMinimumHeight() As Integer
Return MyBase.FontHeight
End Function

Protected Overrides Function GetPreferredHeight(ByVal g As
System.Drawing.Graphics, ByVal value As Object) As Integer
Return GetPreferredSize(g, value).Height
End Function

Protected Overrides Function GetPreferredSize(ByVal g As
System.Drawing.Graphics, ByVal value As Object) As System.Drawing.Size
Dim s As Size
s = Size.Ceiling(g.MeasureString(value.ToString,
MyBase.DataGridTableStyle.DataGrid.Font))
s.Width += 5
Return s
End Function

Protected Overloads Overrides Sub Paint(ByVal g As
System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal
source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer)
End Sub

Protected Overloads Overrides Sub Paint(ByVal g As
System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal
source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer,
ByVal alignToRight As Boolean)
End Sub

Protected Overloads Overrides Sub Paint(ByVal g As
System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal
source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer,
ByVal backBrush As System.Drawing.Brush, ByVal foreBrush As
System.Drawing.Brush, ByVal alignToRight As Boolean)

Dim r As New RectangleF(bounds.X, bounds.Y, bounds.Width,
bounds.Height)
Dim value As Object = MyBase.GetColumnValueAtRow(source, rowNum)
Dim f As Font = MyBase.DataGridTableStyle.DataGrid.Font
Dim format As New StringFormat

If source.Position = rowNum Then

Dim bb As New
SolidBrush(MyBase.DataGridTableStyle.SelectionBackColor)
Dim fb As New
SolidBrush(MyBase.DataGridTableStyle.SelectionForeColor)

g.FillRectangle(bb, r)

If TypeOf value Is Boolean Then
Dim state As ButtonState
If CType(value, Boolean) Then
state = ButtonState.Checked
Else
state = ButtonState.Normal
End If
ControlPaint.DrawCheckBox(g, bounds, state)
Else
g.DrawString(value.ToString, f, fb, r, format)
End If

bb.Dispose()
fb.Dispose()

Else

g.FillRectangle(backBrush, r)

If TypeOf value Is Boolean Then
Dim state As ButtonState
If CType(value, Boolean) Then
state = ButtonState.Checked
Else
state = ButtonState.Normal
End If
ControlPaint.DrawCheckBox(g, bounds, state)
Else
g.DrawString(value.ToString, f, foreBrush, r, format)
End If

End If

End Sub

End Class

Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo

Preguntas similares