VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Customize flex Grid

by liaqat fayyaz (10 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 8th May 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Customize flex Grid

Rate Customize flex Grid




Private Sub cmdSubmit_Click()
  If txtValue <> "" Then
    grd.Row = cmbRow
    grd.Col = cmbCol
    grd.CellAlignment = cmbAlign.ItemData(cmbAlign.ListIndex)
    grd.Text = FormatIt(txtValue)
  End If
End Sub

Private Sub Form_Load()
  Dim i As Integer
  Dim ctrl As Control
  
  For i = 1 To grd.Rows - 1
    cmbRow.AddItem i
  Next
  For i = 1 To grd.Cols - 1
    cmbCol.AddItem i
  Next
  With cmbAlign
    .AddItem "Left"
    .ItemData(.NewIndex) = 1
    .AddItem "Center"
    .ItemData(.NewIndex) = 4
    .AddItem "Right"
    .ItemData(.NewIndex) = 7
  End With
  cmbFormat.AddItem "American number"
  cmbFormat.AddItem "Europian number"
  
  For Each ctrl In Me.Controls
    If TypeOf ctrl Is ComboBox Then ctrl.ListIndex = 0
  Next
End Sub

Private Sub grd_Click()
  cmbCol = grd.Col
  cmbRow = grd.Row
  txtValue = grd.Text
End Sub

Private Function FormatIt(ByVal s As String) As String
  Dim DecimalChar As String
  Dim ThousandChar As String
  Dim i As Integer: Dim temp As String
  
  Select Case cmbFormat.ListIndex
  Case 0
    DecimalChar = "."
    ThousandChar = ","
  Case 1
    DecimalChar = ","
    ThousandChar = "."
  End Select
  If InStr(s, DecimalChar) > 0 Then
    i = Len(Mid(s, InStr(s, DecimalChar) + 1))
    Select Case i
      Case 0: s = s & "00"
      Case 1: s = s & "0"
      Case Else: s = Left(s, Len(s) - (i - 2))
    End Select
  Else
    s = s & DecimalChar & "00"
  End If
  If InStr(s, ThousandChar) > 0 Then
    temp = Mid(s, InStr(s, ThousandChar) + 1)
    If Len(Left(temp, InStr(temp, DecimalChar) - 1)) < 3 Then _
      s = Left(s, InStr(s, ThousandChar) - 1) & Mid(s, InStr(s, ThousandChar) + 1)
  End If
  If InStr(s, ThousandChar) = 0 Then
    i = Len(Left(s, InStr(s, DecimalChar) - 1))
    If i > 3 Then s = Left(s, i - 3) & ThousandChar & Mid(s, i - 2)
  End If
  FormatIt = s
End Function


Download this snippet    Add to My Saved Code

Customize flex Grid Comments

No comments have been posted about Customize flex Grid. Why not be the first to post a comment about Customize flex Grid.

Post your comment

Subject:
Message:
0/1000 characters