...più o meno una cosa così ?
Public Sub Form_Open()
With TableView1
.Rows.Count = 3
.Columns.Count = 2
End With
End
Public Sub TableView1_KeyRelease()
Select Key.Code
Case 48 To 57
TableView1[0, 0].Text = Chr(Key.Code)
Case 65 To 90
TableView1[0, 1].Text = Chr(Key.Code)
End Select
End
Propongo questo codice, ma forse è inutile e troppo complicato :-\
' Gambas class file
Private hTable As TableView
Public Sub Form_Open()
Me.Arrangement = Arrange.Fill
Me.Margin = True
hTable = New TableView(Me) As "TableView1"
With hTable
.Header = 3
.Columns.Count = 3
.Rows.count = 10
.Columns[0].Text = "NORMALE"
.Columns[1].Text = "NUMERO"
.Columns[2].Text = "MAIUSCOLO"
End With
End
Public Sub TableView1_Click()
hTable.Edit
End
Public Sub TableView1_Save(Row As Integer, Column As Integer, Value As String)
If column = 1 Then
If Value = soloNumero(Value) Then
hTable[row, column].text = value
hTable[row, column].Background = Color.White
Else
hTable[row, column].text = ""
hTable[row, column].Background = Color.SoftRed
Endif
Else If column = 2 Then
hTable[row, column].text = string.UCase(Value)
Else
hTable[row, column].text = value
Endif
End
Public Function soloNumero(value As String) As String
Dim n As Integer
Dim res As String = ""
For n = 0 To Len(value) - 1
If InStr("0123456789.-", value[n]) Then res &= value[n]
Next
Return IIf(res = "", "0", res)
End
Ho preso a prestito il codice di Pastrank qui:
https://www.gambas-it.org/smf/index.php?topic=8660.msg50502#msg50502
Ho variato leggermente la sub save per segnalare l'errore
...
con la textbox utilizzando l'evento keypress e change è possibile fare questo, ma con la tableview non sono riuscito a risolvere nulla.
Dimenticavo potresti usare:
TableView1.EditWith(TextBox1)
Ora non ho tempo, scappo a dormire che domani ho delle commissioni da fare, notte
Ciao grazie per le risposte ho risolto in parte, con il codice proposto da Gianluigi sono riuscito a risolvere il maiuscolo implementando la regolazione automatica dell'altezza riga:
Public Sub TableView1_Save(Row As Integer, Column As Integer, Value As String)
If Column = 1 Then
TableView1[Row, Column].Text = Upper(Value)
Else
TableView1[Row, Column].Text = Value
End If
TableView1[Row, Column].WordWrap = True
TableView1.Rows[Row].Height = -1
End
mentre con il codice di Vuott sembra che gli eventi keypress e keyrelease sulla tableview non abbiano alcun effetto.
sto cercando di implementare questa funzione:
Public Function Numeri()
'solo numeri
If Key.Code >= 48 And Key.Code <= 57 Then
Else If key.Code = key.BackSpace Then
Else If key.Code = key.Delete Then
Else If Key.Code = Key.Left Then
Else If Key.code = Key.Right Then
Else If Key.Code = Key.Tab Then
Else
Stop Event
End If
End
per la gestione dei numeri, praticamente mi dovrebbe far utilizzare solo la parte numerica e alcuni tasti. Per il momento grazie :ciao:
Come ti avevo suggerito puoi usare editwith con una textbox:
' Gambas class file
Private hTable As TableView
Private hText As TextBox
Public Sub Form_Open()
Me.Arrangement = Arrange.Fill
Me.Margin = True
hText = New TextBox(Me) As "TextBox1"
hText.Visible = False
hTable = New TableView(Me) As "TableView1"
With hTable
.Header = 3
.Columns.Count = 3
.Rows.count = 10
.Columns[0].Text = "NORMALE"
.Columns[1].Text = "NUMERO"
.Columns[2].Text = "MAIUSCOLO"
End With
End
Public Sub TableView1_Click()
hTable.EditWith(hText)
End
Public Sub TableView1_Save(Row As Integer, Column As Integer, Value As String)
hTable[row, column].text = value
End
Public Sub TextBox1_Change()
If hTable.Column = 1 Then
hText.Text = soloNumero(hText.Text)
Else If hTable.Column = 2 Then
hText.Text = String.UCase(hText.Text)
Endif
End
Private Function soloNumero(value As String) As String
Dim n As Integer
Dim res As String = ""
For n = 0 To Len(value) - 1
If InStr("0123456789.-", value[n]) Then res &= value[n]
Next
Return res
End
Ti conviene usare String.Ucase e non Upper , per capire prova a scrivere città nella colonna maiuscolo.
Grandioso! mi piace il codice, grazie Gianluigi, l'ho modificato in questo modo:
Private hTable As TableView
Private hText As TextBox
Public Sub Form_Open()
Me.Arrangement = Arrange.Fill
Me.Margin = True
hText = New TextBox(Me) As "TextBox1"
hText.Visible = False
hTable = New TableView(Me) As "TableView1"
With hTable
.Header = 3
.Columns.Count = 3
.Rows.count = 10
.Columns[0].Text = "NORMALE"
.Columns[1].Text = "NUMERO"
.Columns[2].Text = "MAIUSCOLO"
End With
End
Public Sub TableView1_Click()
hTable.EditWith(hText)
End
Public Sub TableView1_Save(Row As Integer, Column As Integer, Value As String)
hTable[row, column].text = value
hTable[Row, Column].WordWrap = True
hTable.Rows[Row].Height = -1 'regola in automatico altezza cella
End
Public Sub TextBox1_Change()
If hTable.column = 1 Then
If hText.text > "" Then
hText.text = Format(Replace(hText.Text, ",", Null) / 100, "0.00") ' virgola in automatico inserimento euro
Endif
Else If hTable.Column = 2 Then
hText.Text = String.UCase(hText.Text)
Endif
End
Public Sub TextBox1_keypress()
If hTable.Column = 1 Then
mod_set.Numeri
Endif
End
'modulo mod_set
Public Function Numeri()
'solo numeri
If Key.Code >= 48 And Key.Code <= 57 Then
Else If key.Code = key.BackSpace Then
Else If key.Code = key.Delete Then
Else If Key.Code = Key.Left Then
Else If Key.code = Key.Right Then
Else If Key.Code = Key.Tab Then
Else
Stop Event
End If
End
funziona egregiamente
P.s. non mi sarebbe mai venuto in mente di usare una textbox. ;D :ciao: