Newsgroup: it.comp.lang.visual-basic
Titolo: [?] Combobox in una griglia

Sono nuovo di VB e anche del NG (che mi pare fantastico!)Ho visto in un prg
una griglia che, quando si clicca su una casella, questa si trasforma in una
combobox.
Potete dirmi come si fa?
Grazie
Matteo

 ha scritto

Un esempio con un controllo TextBox ed un controllo Grid. In questo caso e'
l'evento DblClick che permette l'editazione. Dato che sono pezzi di codice
che ho prelevato da miei programmi assemblandoli al volo puo' darsi che non
tutto fili liscio e che ci sia qualcosa di inutile o che qualcosa manchi.
Copia il tutto in un form e togli il bordo al TextBox.
Option Explicit
Private im_GridCurRow  As Integer
Private im_GridCurCol  As Integer
Private sm_GridCurText As String
Private Sub Form_Load( _
)
Dim i As Integer
  With Me
    With .Grid1
      Let .Rows = 2
      Let .Cols = 11
      Let .FixedRows = 0
      Let .FixedCols = 0
      Let .SelStartRow = 0
      Let .SelStartCol = 0
      Let .SelEndRow = .SelStartRow
      Let .SelEndCol = .Cols - 1
      Let .Clip = _
        "Name" & vbTab & "Type" & vbTab _
        & "Field" & vbTab & "Start" & vbTab _
        & "Len" & vbTab & "HSI" & vbTab _
        & "Delim" & vbTab & "QStr" & vbTab _
        & "Trim" & vbTab & "ISI" _
        & vbTab & "Skip"
      Let .FixedRows = 1
      Let .Row = 0
      For i = 0 To .Cols - 1
        Select Case i
        Case 3, 4
          Let .ColAlignment(i) = 1
        Case 5, 6, 7, 8, 9, 10
          Let .ColAlignment(i) = 2
        Case Else
        End Select
        Let .Col = i
        Let .ColWidth(i) = Me.TextWidth(.Text) + 120
      Next
      Let .SelStartRow = .FixedRows
      Let .SelEndRow = .SelStartRow
      Let .SelStartCol = .FixedCols
      Let .SelEndCol = .SelStartCol
      Let .Row = .FixedRows
      Let .Col = .FixedCols
    End With
    Let .Text1.Visible = False
  End With
End Sub
Private Sub Grid1_DblClick( _
)
Dim i                  As Integer
Dim f_GridLineWidth    As Single
Dim f_GridLineHeight   As Single
Dim f_GridBorderWidth  As Single
Dim f_GridBorderHeight As Single
Dim f_Left             As Single
Dim f_Top              As Single
Dim f_Width            As Single
  With Me
    With .Grid1
      Let im_GridCurRow = .Row
      Let im_GridCurCol = .Col
      Let sm_GridCurText = .Text
      Let f_GridBorderWidth _
        = Screen.TwipsPerPixelX _
        * .BorderStyle
      Let f_GridBorderHeight _
        = Screen.TwipsPerPixelY _
        * .BorderStyle
      Let f_GridLineWidth _
        = Screen.TwipsPerPixelX _
        * .GridLineWidth _
        * .GridLines
      Let f_GridLineHeight _
        = Screen.TwipsPerPixelY _
        * .GridLineWidth _
        * .GridLines
      ' //  Left
      Let f_Left _
        = 2 * f_GridBorderWidth _
        + .Left
      For i = .LeftCol To im_GridCurCol - 1
        Let f_Left _
          = f_Left _
          + .ColWidth(i) _
          - f_GridLineWidth
      Next
      Let f_Left = f_Left - f_GridLineWidth
      ' //  Top
      Let f_Top _
        = 2 * f_GridBorderHeight _
        + .Top _
        + .RowHeight(0)
      For i = .TopRow To .Row - 1
        Let f_Top _
          = f_Top _
          + .RowHeight(i) _
          - f_GridLineHeight
      Next
      Let f_Top = f_Top - f_GridLineHeight
      ' //  Width
      Let f_Width _
        = .ColWidth(im_GridCurCol) _
        + 2 * f_GridLineWidth
    End With
    With .Text1
      Call .Move( _
          f_Left _
        , f_Top _
        , f_Width)
      Let .Text = ""
      Let .Visible = True
      Call .SetFocus
    End With
  End With
End Sub
Private Sub Text1_GotFocus( _
)
  With Me.Text1
    Let .Text = sm_GridCurText
    Let .SelStart = 0
    Let .SelLength = Len(.Text)
  End With
End Sub
Private Sub Text1_LostFocus( _
)
Dim i_Row   As Integer
Dim i_Col   As Integer
Dim s_Text  As String
  With Me.Grid1
    Let i_Row = .Row
    Let .Row = im_GridCurRow
    Let i_Col = .Col
    Let .Col = im_GridCurCol
    With Me.Text1
      If .Text = sm_GridCurText Then
        Let s_Text = sm_GridCurText
      Else
        Let s_Text = .Text
      End If
      Let .Visible = False
    End With
    Let .Text = s_Text
    Let .Row = i_Row
    Let .Col = i_Col
  End With
End Sub
--
Ciao.
Maurizio