Como usar Msflexgrid en vb net...Codigo Puesto

Denis Guido
17 de Marzo del 2004
Option Strict Off
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
#Region "Código generado por el Diseñador de Windows Forms "
Public Sub New()
MyBase.New()
If m_vb6FormDefInstance Is Nothing Then
If m_InitializingDefInstance Then
m_vb6FormDefInstance = Me
Else
Try
'Para el formulario de inicio, la primera instancia creada es la instancia predeterminada.
If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
m_vb6FormDefInstance = Me
End If
Catch
End Try
End If
End If
'El Diseñador de Windows Forms requiere esta llamada.
InitializeComponent()
End Sub
'Form reemplaza a Dispose para limpiar la lista de componentes.
Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
If Disposing Then
If Not components Is Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(Disposing)
End Sub
'Requerido por el Diseñador de Windows Forms
Private components As System.ComponentModel.IContainer
Public ToolTip1 As System.Windows.Forms.ToolTip
Public WithEvents txtEditaCelda As System.Windows.Forms.TextBox
Public WithEvents msfG As AxMSFlexGridLib.AxMSFlexGrid
'NOTA: el siguiente procedimiento es necesario para el Diseñador de Windows Forms
'Se puede modificar mediante el Diseñador de Windows Forms.
'No lo modifique con el editor de código.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.txtEditaCelda = New System.Windows.Forms.TextBox
Me.msfG = New AxMSFlexGridLib.AxMSFlexGrid
CType(Me.msfG, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'txtEditaCelda
'
Me.txtEditaCelda.AcceptsReturn = True
Me.txtEditaCelda.AutoSize = False
Me.txtEditaCelda.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(192, Byte))
Me.txtEditaCelda.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.txtEditaCelda.Cursor = System.Windows.Forms.Cursors.IBeam
Me.txtEditaCelda.ForeColor = System.Drawing.SystemColors.WindowText
Me.txtEditaCelda.Location = New System.Drawing.Point(24, 240)
Me.txtEditaCelda.MaxLength = 0
Me.txtEditaCelda.Name = "txtEditaCelda"
Me.txtEditaCelda.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.txtEditaCelda.Size = New System.Drawing.Size(65, 19)
Me.txtEditaCelda.TabIndex = 1
Me.txtEditaCelda.Text = ""
'
'msfG
'
Me.msfG.Location = New System.Drawing.Point(16, 32)
Me.msfG.Name = "msfG"
Me.msfG.OcxState = CType(resources.GetObject("msfG.OcxState"), System.Windows.Forms.AxHost.State)
Me.msfG.Size = New System.Drawing.Size(473, 200)
Me.msfG.TabIndex = 0
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.Desktop
Me.ClientSize = New System.Drawing.Size(568, 334)
Me.Controls.Add(Me.txtEditaCelda)
Me.Controls.Add(Me.msfG)
Me.Cursor = System.Windows.Forms.Cursors.Default
Me.Location = New System.Drawing.Point(4, 30)
Me.Name = "Form1"
Me.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Text = "Form1"
CType(Me.msfG, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub
#End Region
#Region "Soporte para la actualización "
Private Shared m_vb6FormDefInstance As Form1
Private Shared m_InitializingDefInstance As Boolean
Public Shared Property DefInstance() As Form1
Get
If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
m_InitializingDefInstance = True
m_vb6FormDefInstance = New Form1()
m_InitializingDefInstance = False
End If
DefInstance = m_vb6FormDefInstance
End Get
Set
m_vb6FormDefInstance = Value
End Set
End Property
#End Region
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
txtEditaCelda.Height = VB6.TwipsToPixelsY(msfG.CellHeight)
txtEditaCelda.Height = VB6.TwipsToPixelsY(msfG.CellHeight)
txtEditaCelda.Width = VB6.TwipsToPixelsX(msfG.CellWidth)
txtEditaCelda.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(msfG.Left) + msfG.CellLeft)
txtEditaCelda.Top = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(msfG.Top) + msfG.CellTop)
txtEditaCelda.Visible = True
txtEditaCelda.Text = msfG.get_TextMatrix(msfG.RowSel, msfG.ColSel)
txtEditaCelda.SelectionStart = 0
txtEditaCelda.SelectionLength = Len(txtEditaCelda.Text)
msfG.set_ColWidth(1, 3000)
End Sub
Private Sub msfG_EnterCell(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles msfG.EnterCell
If msfG.get_ColWidth(msfG.Col) > 0 And msfG.get_RowHeight(msfG.Row) > 0 Then ColocaText()
End Sub
'UPGRADE_WARNING: El evento txtEditaCelda.TextChanged se puede desencadenar cuando se inicializa el formulario. Haga clic aquí para obtener más información: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2075"'
Private Sub txtEditaCelda_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtEditaCelda.TextChanged
msfG.Text = txtEditaCelda.Text
End Sub
Private Sub txtEditaCelda_KeyDown(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyEventArgs) Handles txtEditaCelda.KeyDown
Dim KeyCode As Short = eventArgs.KeyCode
Dim Shift As Short = eventArgs.KeyData &H10000
Select Case KeyCode
Case System.Windows.Forms.Keys.Up
Do While msfG.Row > msfG.FixedRows
msfG.Row = msfG.Row - 1
If msfG.get_RowHeight(msfG.Row) > 0 Then Exit Do
Loop
KeyCode = 0
Case System.Windows.Forms.Keys.Down
Do While msfG.Row < msfG.Rows - 1
msfG.Row = msfG.Row + 1
If msfG.get_RowHeight(msfG.Row) > 0 Then Exit Do
Loop
KeyCode = 0
Case System.Windows.Forms.Keys.Left
Do While msfG.Col > msfG.FixedCols
msfG.Col = msfG.Col - 1
If msfG.get_ColWidth(msfG.Col) > 0 Then Exit Do
Loop
KeyCode = 0
Case System.Windows.Forms.Keys.Right
Do While msfG.Col < msfG.Cols - 1
msfG.Col = msfG.Col + 1
If msfG.get_ColWidth(msfG.Col) > 0 Then Exit Do
Loop
KeyCode = 0
Case System.Windows.Forms.Keys.Tab Or 13
Do While msfG.Col < msfG.Cols - 1
msfG.Col = msfG.Col + 1
If msfG.get_ColWidth(msfG.Col) > 0 Then Exit Do
Loop
KeyCode = 0

End Select
End Sub
' Coloca el textBox sobre la celda actual
Private Sub ColocaText()
With txtEditaCelda
.SetBounds(VB6.TwipsToPixelsX(msfG.CellLeft + VB6.PixelsToTwipsX(msfG.Left)), VB6.TwipsToPixelsY(msfG.CellTop + VB6.PixelsToTwipsY(msfG.Top)), VB6.TwipsToPixelsX(msfG.CellWidth), VB6.TwipsToPixelsY(msfG.CellHeight))
.Visible = True
.BringToFront()
.Text = msfG.Text
.Focus()
.SelectionStart = 0
.SelectionLength = Len(msfG.Text)
End With
End Sub
End Class


Objetos utilizado cuadro de texto y un msflexgrid


Denis guido