jars05
Recien Llegado

Desconectado
Mensajes: 3
|
 |
« Respuesta #1 en: Agosto 01, 2007, 05:01:50 » |
|
hey mano soy yo jars05 hay le mando un codigo para un flexgrid editable Option Explicit
Private Sub Form_Load() Dim r As Integer Dim c As Integer Dim max_len As Single Dim new_len As Single
' Use no border. Text1.BorderStyle = vbBSNone
' Match the grid's font. Text1.FontName = MSFlexGrid1.FontName Text1.FontSize = MSFlexGrid1.FontSize Text1.Visible = False
' Create some data. MSFlexGrid1.FixedCols = 0 MSFlexGrid1.Cols = 5 MSFlexGrid1.FixedRows = 1 MSFlexGrid1.Rows = 6
MSFlexGrid1.TextMatrix(0, 0) = "Name" MSFlexGrid1.TextMatrix(0, 1) = "Street" MSFlexGrid1.TextMatrix(0, 2) = "City" MSFlexGrid1.TextMatrix(0, 3) = "State" MSFlexGrid1.TextMatrix(0, 4) = "Zip"
MSFlexGrid1.TextMatrix(1, 0) = "Andy Avaricious" MSFlexGrid1.TextMatrix(1, 1) = "827 Problem Blvd" MSFlexGrid1.TextMatrix(1, 2) = "Paranoia City" MSFlexGrid1.TextMatrix(1, 3) = "CA" MSFlexGrid1.TextMatrix(1, 4) = "98765"
MSFlexGrid1.TextMatrix(2, 0) = "Betty Boisterous" MSFlexGrid1.TextMatrix(2, 1) = "4352 Main St Apt 254" MSFlexGrid1.TextMatrix(2, 2) = "Langonsville" MSFlexGrid1.TextMatrix(2, 3) = "VT" MSFlexGrid1.TextMatrix(2, 4) = "01234"
MSFlexGrid1.TextMatrix(3, 0) = "Charles Cheerful" MSFlexGrid1.TextMatrix(3, 1) = "89 North A Ln" MSFlexGrid1.TextMatrix(3, 2) = "Codertown" MSFlexGrid1.TextMatrix(3, 3) = "MN" MSFlexGrid1.TextMatrix(3, 4) = "54583"
MSFlexGrid1.TextMatrix(4, 0) = "Denise Delightful" MSFlexGrid1.TextMatrix(4, 1) = "89 75th" MSFlexGrid1.TextMatrix(4, 2) = "Bugvanna" MSFlexGrid1.TextMatrix(4, 3) = "WY" MSFlexGrid1.TextMatrix(4, 4) = "82738"
MSFlexGrid1.TextMatrix(5, 0) = "Ed Enlightened" MSFlexGrid1.TextMatrix(5, 1) = "2765 N South St E" MSFlexGrid1.TextMatrix(5, 2) = "Abend" MSFlexGrid1.TextMatrix(5, 3) = "TX" MSFlexGrid1.TextMatrix(5, 4) = "67583"
' Size the columns. Font.Name = MSFlexGrid1.Font.Name Font.Size = MSFlexGrid1.Font.Size For c = 0 To MSFlexGrid1.Cols - 1 max_len = 0 For r = 0 To MSFlexGrid1.Rows - 1 new_len = TextWidth(MSFlexGrid1.TextMatrix(r, c)) If max_len < new_len Then max_len = new_len Next r MSFlexGrid1.ColWidth(c) = max_len + 240 MSFlexGrid1.ColAlignment(c) = flexAlignLeftCenter Next c
MSFlexGrid1.AllowUserResizing = flexResizeBoth End Sub Private Sub GridEdit(KeyAscii As Integer) ' Position the TextBox over the cell. Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top Text1.Width = MSFlexGrid1.CellWidth Text1.Height = MSFlexGrid1.CellHeight Text1.Visible = True Text1.SetFocus
Select Case KeyAscii Case 0 To Asc(" ") Text1.Text = MSFlexGrid1.Text Text1.SelStart = Len(Text1.Text) Case Else Text1.Text = Chr$(KeyAscii) Text1.SelStart = 1 End Select End Sub
Private Sub Form_Resize() MSFlexGrid1.Move 0, 0, ScaleWidth, ScaleHeight End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode Case vbKeyEscape ' Leave the text unchanged. Text1.Visible = False MSFlexGrid1.SetFocus
Case vbKeyReturn ' Finish editing. MSFlexGrid1.SetFocus
Case vbKeyDown ' Move down 1 row. MSFlexGrid1.SetFocus DoEvents If MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 Then MSFlexGrid1.Row = MSFlexGrid1.Row + 1 End If
Case vbKeyUp ' Move up 1 row. MSFlexGrid1.SetFocus DoEvents If MSFlexGrid1.Row > MSFlexGrid1.FixedRows Then MSFlexGrid1.Row = MSFlexGrid1.Row - 1 End If
End Select End Sub ' Do not beep on Return or Escape. Private Sub Text1_KeyPress(KeyAscii As Integer) If (KeyAscii = vbKeyReturn) Or _ (KeyAscii = vbKeyEscape) _ Then KeyAscii = 0 End Sub Private Sub MSFlexGrid1_DblClick() GridEdit Asc(" ") End Sub
Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer) GridEdit KeyAscii End Sub
Private Sub MSFlexGrid1_LeaveCell() If Text1.Visible Then MSFlexGrid1.Text = Text1.Text Text1.Visible = False End If End Sub Private Sub MSFlexGrid1_GotFocus() If Text1.Visible Then MSFlexGrid1.Text = Text1.Text Text1.Visible = False End If End Sub
|