-
Oct 24th, 2024, 02:10 PM
#1441
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Update released.
Included enum FlexClipModeLookupConv/FlexClipModeLookupConvExcludeHidden for the ClipMode property.
This translates to Value in Get .Clip and to Key in Let .Clip. (Method AddItem also affected)
The translation only occurs if a column has a lookup defined.
The VBFLXGRD18.OCX was also updated to enrich the FlexClipModeConstants. (type lib edit)
-
Nov 1st, 2024, 04:05 AM
#1442
Addicted Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Hi, thanks, and.. how did you solved the sort problem ?
or you are not allowing the user to sort the rows ?
-
Nov 1st, 2024, 06:53 AM
#1443
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Calcu
Hi, thanks, and.. how did you solved the sort problem ?
or you are not allowing the user to sort the rows ?
What problem? And what allowing?
-
Nov 1st, 2024, 07:55 AM
#1444
Addicted Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Sorry, i was answering pietrov.
I'm trying to do the same (1 master line and 4 or 5 child lines), and this lines Will be hidden, they only Will be shown if first column is clicked (that is working, is easy), but how can a user sort column number 3 (for example) and the hidden rows still under it's master line?
-
Nov 1st, 2024, 08:01 AM
#1445
Addicted Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
That's the code i'm using to hide/show the lines:
Code:
Private Sub Gr1_CellClick(ByVal Row As Long, ByVal Col As Long, ByVal Button As Integer)
Dim X As Long
Dim xExpandiendo As Boolean
With Gr1
If Col = .ColIndex("desplegar") Then
If .TextMatrix(Row, .ColIndex("desplegar")) = "+" Then
xExpandiendo = True
Else
xExpandiendo = False
End If
For X = 1 To .rows - 1
If xExpandiendo = True Then
If .TextMatrix(X, .ColIndex("numcli")) = .TextMatrix(Row, .ColIndex("numcli")) Then
If .TextMatrix(X, .ColIndex("tipolinea")) = "padre" Then
.TextMatrix(X, .ColIndex("desplegar")) = "-"
End If
.RowHidden(X) = False
End If
Else
If .TextMatrix(X, .ColIndex("numcli")) = .TextMatrix(Row, .ColIndex("numcli")) Then
If .TextMatrix(X, .ColIndex("tipolinea")) = "padre" Then
.TextMatrix(X, .ColIndex("desplegar")) = "+"
.RowHidden(X) = False
Else
.RowHidden(X) = True
End If
End If
End If
Next X
End If
End With
End Sub
But (for example if column 3 has... "kilos" (numeric), and i sort this column, the hidden rows (tipolinea = hijos) are not below the main row (tipolinea = padre) anymore.
i want to sort using the sort properties from the grid, not reloading the recordset again (that should be easy)
-
Nov 1st, 2024, 02:13 PM
#1446
New Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Calcu
Hi, thanks, and.. how did you solved the sort problem ?
or you are not allowing the user to sort the rows ?
Hello Calcu,
the grid that I show in my previous post is populated row by row reading data from a recordset, the user has no live interaction with the sorting of the grid once it has been populated, the user can only expand or collapse the subrows.
During the population of the grid, I use the Celltag property of the first cell of each row to store a value that distinguish the "top level rows" from the "sub-rows": top level rows have 1 or 0 depending if they are collapsed (1) or expanded (0), sub rows just have 'sub' to identify them.
I allow the user to click any cell of the row to expand or collapse, while if a sub row is clicked, I just put the image of a selector in the first cell and enable a button to watch something related to that row.
Once a top level row is clicked, all the following sub-rows are hidden or shown until I hit another high level row or the end of the grid.
Hope this helps
Code:
Private Sub grHistory_CellClick(ByVal Row As Long, ByVal col As Long, ByVal Button As Integer)
With grHistory
If Row > 0 Then
'enable the click on any cell of the row: read the tag of the first cell
.col = 0
'check if the tag is collapsed or expanded
If .CellTag = "1" Then
'expand
.CellTag = "0"
.CellPicture = frmMain.imgList.ListImages("butt-dn").Picture
Call ExpandCollapse(Row, True)
ElseIf .CellTag = "0" Then
'collapse
.CellTag = "1"
.CellPicture = frmMain.imgList.ListImages("butt-rx").Picture
Call ExpandCollapse(Row, False)
'check if the actualrow is collapsed, in which case clear it
If Actualrow > 0 Then
If .RowHidden(Actualrow) Then
.Row = Actualrow
.col = 0
.CellPicture = Nothing
Actualrow = 0
End If
End If
ElseIf .CellTag = "sub" Then
'this is a subrow, just select it and remove the picture on previous row
If Actualrow > 0 Then
.Row = Actualrow
.col = 0
.CellPicture = Nothing
End If
Actualrow = Row
.Row = Row
.col = 0
.CellPicture = frmMain.imgList.ListImages("selector").Picture
.CellPictureAlignment = FlexPictureAlignmentRightCenter
End If
End If
Me.cmdWatch.Enabled = (Actualrow > 0)
End With
End Sub
Private Sub ExpandCollapse(Row As Long, exp As Boolean)
Dim nr As Long
With grHistory
nr = Row + 1
Do While nr <= .Rows - 1
.Row = nr
.col = 0
If Left(.CellTag, 3) = "sub" Then
.RowHidden(nr) = Not exp
nr = nr + 1
Else
Exit Do
End If
Loop
End With
End Sub
-
Nov 4th, 2024, 07:24 AM
#1447
Addicted Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
@krool, it's possible to sort a grid on 2 columns at the same time ?
I mean, sort by col1 + col3
If we can do this, the problem i have is solved, i will sort first for the asked column and then for the index column, then the order will be maintained.
I used:
.cell(FlexCellSort, .FixedRows, LastColSort, .rows - 1, LastColSort) = FlexSortUseColSort
.cell(FlexCellSort, .FixedRows, 5, .rows - 1, 5) = FlexSortUseColSort
.cell(FlexCellSort, .FixedRows, 6, .rows - 1, 6) = FlexSortUseColSort
where lastcolsort is the one selected by user, and then cols 5 and 6, but it's not working as expected.
I'll do more tests
Last edited by Calcu; Nov 4th, 2024 at 07:37 AM.
-
Nov 4th, 2024, 08:19 AM
#1448
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Calcu
@krool, it's possible to sort a grid on 2 columns at the same time ?
I mean, sort by col1 + col3
If we can do this, the problem i have is solved, i will sort first for the asked column and then for the index column, then the order will be maintained.
I used:
.cell(FlexCellSort, .FixedRows, LastColSort, .rows - 1, LastColSort) = FlexSortUseColSort
.cell(FlexCellSort, .FixedRows, 5, .rows - 1, 5) = FlexSortUseColSort
.cell(FlexCellSort, .FixedRows, 6, .rows - 1, 6) = FlexSortUseColSort
where lastcolsort is the one selected by user, and then cols 5 and 6, but it's not working as expected.
I'll do more tests
if the 2 columns are "together" you can sort in 1 step.
If there are not together, like in your case, then yes you need to sort in 2 steps. (first the minor sort column and then the major sort column)
-
Nov 4th, 2024, 10:18 AM
#1449
Addicted Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Perfect, done.
Now it will be perfect if a cell is hidden, don't use it when sorting.
Just only sort if a cell is visible.
-
Nov 4th, 2024, 12:20 PM
#1450
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Calcu
Perfect, done.
Now it will be perfect if a cell is hidden, don't use it when sorting.
Just only sort if a cell is visible.
Don't understand. Even when a row is hidden it will remain hidden after sort.
-
Nov 4th, 2024, 01:14 PM
#1451
Addicted Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Yes, but i'm trying to do this:
Normal grid:
Expanded:
if you see the three firsts rows in expanded view, are from the same Client (column 2).
if the user sorts by this column, the order will be 3 - 4 - 5 -1 - 2 rows
then i'm forcing to sort by columns: 3 + 2 + last (user selected), and it's here when the main order is changed because the last column sort.
If the hidden cells aren't used for sort, the result will be the expected (order by the column selected by the user + the client nuember (forced by me) + the code (forced by me))
Edit (fixed images)
Last edited by Calcu; Nov 5th, 2024 at 03:19 AM.
-
Nov 4th, 2024, 04:03 PM
#1452
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Last edited by Krool; Nov 6th, 2024 at 02:15 PM.
-
Nov 6th, 2024, 02:15 PM
#1453
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Calcu
Perfect, done.
Now it will be perfect if a cell is hidden, don't use it when sorting.
Just only sort if a cell is visible.
It's not possible to make a sorting to achieve what you want. Yes, we can do a FlexSortCustom and return Cmp = 0 when both rows are hidden but this will not result in what you want.
In fact, you would need to just do a sort and then "move" (= RowPosition) your hidden rows back to your "group". Those hidden rows should all have the same value in the sorted column so that they will remain relative order.
-
Nov 6th, 2024, 04:22 PM
#1454
Addicted Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Ok. Let's try tomorrow with rowposition.
Thanks for everything, let's see if can do It xD
-
Nov 7th, 2024, 07:13 AM
#1455
Addicted Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
If someone needs the code (i'm open to improvements :-) )
i used:
Code:
Private Sub ReorganizarClientesPorCentro(Grid As VBFlexGrid)
Dim numero_cliente_actual As String
Dim i As Long, j As Long
Dim ultima_posicion_centro01 As Long
Grid.Redraw = False
For i = Grid.rows - 1 To 1 Step -1
If Grid.TextMatrix(i, Grid.ColIndex("codcli")) = "01" Then 'Or Grid.TextMatrix(i, Grid.ColIndex("codcli")) = "" Then
numero_cliente_actual = Grid.TextMatrix(i, Grid.ColIndex("numcli"))
ultima_posicion_centro01 = i
' Recorre nuevamente el grid para ubicar y mover los centros adicionales
For j = 1 To Grid.rows - 1
If Grid.TextMatrix(j, Grid.ColIndex("numcli")) = numero_cliente_actual And Grid.TextMatrix(j, Grid.ColIndex("codcli")) <> "01" Then
If (ultima_posicion_centro01) + 1 <= (Grid.rows - 1) Then
Grid.RowPosition(j) = ultima_posicion_centro01 + 1
Else
Grid.AddItem "", Grid.rows - 1
Grid.RowPosition(j) = Grid.rows - 1
End If
End If
Next j
End If
Next i
Grid.Redraw = True
End Sub
This code is called with: ReorganizarClientesPorCentro Gr1 just after sort the grid by the user.
And it respects the sort done by the user (for example column ... 4) and then reorganizes the rows taking in account 2 columns (numcli and codcli)
With this, if you have hidden rows and this hidden rows are controlled by this 2 columns (numcli and codcli), they will maintain the order fine
Last edited by Calcu; Nov 7th, 2024 at 11:16 AM.
-
Nov 19th, 2024, 03:22 AM
#1456
Addicted Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Hi all,
A little code if someone needs it.
Code for Drag and drop a cell inside the same grid (of course I’m open to improvements xD)
You need to set AllowSelection to false in order to not see all the cells selected while you are moving the mouse over them.
Declare:
Code:
Private origenRow As Long
Private origenCol As Long
Private Dragging As Boolean
And the events:
Code:
Private Sub GRZonas_BeforeMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single, Cancel As Boolean)
' Detectar la celda de origen
If Button = vbLeftButton Then
With GRZonas
origenRow = .MouseRow
origenCol = .MouseCol
' Asegurarse de que el usuario seleccionó una celda válida
If origenRow > 0 And origenCol > 0 Then
Dragging = True
End If
End With
End If
End Sub
Private Sub GRZonas_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim destinoRow As Long
Dim destinoCol As Long
Dim I As Long
Dim XX As Long
' Detectar la celda de destino
If Dragging Then
With GRZonas
destinoRow = .MouseRow
destinoCol = .MouseCol
' Verificar que no se suelta fuera de rango y no en la misma celda
If destinoRow > 0 And destinoCol > 0 And (destinoRow <> origenRow Or destinoCol <> origenCol) Then
'bucle para que se pegue en la primera celda vacia de la columna
For I = 1 To .rows - 2
If .TextMatrix(I, destinoCol) = "" Then
' Mover datos de origen a destino
.TextMatrix(I, destinoCol) = .TextMatrix(origenRow, origenCol)
.TextMatrix(origenRow, origenCol) = "" ' Limpiar celda de origen (opcional)
'Reorganizar columna original para quitar el blanco si lo hay
For XX = 1 To .rows - 2
If .TextMatrix(XX, origenCol) = "" Then
.TextMatrix(XX, origenCol) = .TextMatrix(XX + 1, origenCol)
.TextMatrix(XX + 1, origenCol) = ""
End If
Next XX
Exit For
End If
Next I
End If
End With
End If
' Restaurar el estado
Dragging = False
End Sub
Last edited by Calcu; Nov 19th, 2024 at 03:44 AM.
-
Dec 10th, 2024, 04:53 PM
#1457
Fanatic Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Hi ,I have placed 3 buttons on the form, one is to show the checkbox(command1), the second is to delete(command2), the third is to hide the checkboxes(command3),My grid reads information from the record using ado data control (ADODC), for example, the second column is the ID, so I want the checkboxes to be displayed next to the ID, so I use the following code:
Code:
' command1
grid1.ColCheckBoxes(1) = True
To hide the checkboxes, I use the following code in the third button:
Code:
' command3
grid1.ColCheckBoxes(1) = False
And to delete the information that I want to delete, I use the following codes:
Code:
' command2
Dim tmpsavedtoprow As Integer
tmpsavedtoprow = grid1.TopRow
Dim c2 As New Collection, i2 As Integer
' for collect ID data fields to use in query for delete them
For i2 = 0 To grid1.Rows - 1
grid1.Col = 1
grid1.Row = i2
If grid1.CellChecked = FlexChecked Then c2.Add grid1.Cell(FlexCellText)
Next
If c2.Count = 0 Then Exit Sub
For i2 = 1 To c2.Count
ad.RecordSource = "select id,data,tepymelk,nva,khnames,sen,idkhab from sample26 where id =" & c2.Item(i2)
ad.Refresh
If ad.Recordset.RecordCount <> 0 Then
ad.Recordset.Delete
ad.Refresh
End If
DoEvents
Sleep 100
Next
Set c2 = Nothing
ad.RecordSource = "select id,data,tepymelk,nva,khnames,sen,idkhab from sample26 order by id"
ad.Refresh
' refreshgrid will be clear grid and again fill data with read from first to end of recordset
Call RereshGrid1(grid1, ad.Recordset)
grid1.Col = 0: grid1.TopRow = tmpsavedtoprow
grid1.Row = tmpsavedtoprow
There are several problems here:
problem1:
If the user clicks on checkboxes or unchecks them, when I click the third button(command3), not all the checkboxes are hidden and the checkboxes that the user has previously checked or unchecked remain. Temporary i used this code, seems this code is not good idea because i guess it will be making process to slow, any better idea for optimize this code for better speed :
Code:
' command3
Dim i3 As Integer
For i3 = 0 To grid1.Rows - 1
grid1.Col = 1
grid1.Row = i3
grid1.CellChecked = FlexNoCheckBox
Next
grid1.ColCheckBoxes(1) = False
How do I solve this problem?
problem2:
i guess this delete process(command2) is not optimize and will be make process to slow when records are alot,there is any idea for better delete speed and fill datagrid faster?
Last edited by Black_Storm; Dec 10th, 2024 at 11:55 PM.
Point one: some fools still do not know the reason why cracked software should be used, companies or people who serve the terrorist or Zionist current must be fought, the current era is the era of soft war (the war of ideology and the battle of thoughts) is more important than hard war.
Point two: foolish thanks are worthless, I am here to shout out the faults so that they will be upset and stop their foolish pride, if you consider yourself strong, stop the death you are heading towards.
point third: some people or countries in the apocalypse era are just spectators, these are the most worthless creatures.
Point Four: NSA is one of the largest spy centers in the world : )) .
Point Five : Age is just a number, sometimes old people are stupider than young people.
-
Dec 11th, 2024, 02:07 AM
#1458
Addicted Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Maybe you can hide the entire column? Grid.colhidden(1)=true
-
Dec 11th, 2024, 02:15 AM
#1459
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
How do you refresh the grid?
Normally you would remove .Rows = .FixedRows or 0 to reset everything before loading new.
-
Dec 11th, 2024, 02:40 AM
#1460
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Why not just remove the checked rows from the grid instead of querying the data again.
When deleting items from the table use a delete query with an "in" clause, much faster then looping through a collection.
And next time start your own thread
-
Dec 11th, 2024, 10:36 PM
#1461
Fanatic Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
I temporarily improved the speed with the help of Arnoutdv's suggestion as follows (while I can only use the ADODC control, and I can't use a library to execute SQL commands, and my grid must also have a column for row numbers):
Code:
Dim tmpsavedtoprow As Integer
tmpsavedtoprow = grid1.TopRow
Dim c2 As New Collection, i2 As Integer
' =============================================
'If there is a faster way to navigate between checked rows, it will definitely be faster and there will be no need to read from the beginning to the end of the grid, especially when the number of records is large.
' =============================================
For i2 = 0 To grid1.Rows - 1
grid1.Col = 1
grid1.Row = i2
If grid1.CellChecked = FlexChecked Then c2.Add grid1.Cell(FlexCellText)
Next
If c2.Count = 0 Then
Set c2 = Nothing
Exit Sub
End If
Dim joinedstring() As String
ReDim joinedstring(c2.Count - 1)
For i2 = 0 To c2.Count - 1
joinedstring(i2) = c2(i2 + 1)
Next
Set c2 = Nothing
Dim tmptstring As String
tmptstring = Join(joinedstring, ",")
Erase joinedstring
ad.RecordSource = "select id from sample26 where id in (" & tmptstring & ")"
tmptstring = ""
ad.Refresh
While ad.Recordset.RecordCount <> 0
ad.Recordset.Delete adAffectCurrent ' marked for delete
ad.Recordset.MoveNext
DoEvents
Wend
ad.Refresh ' delete marked records
ad.RecordSource = "select id,data,tepymelk,nva,khnames,sen,idkhab from sample26 order by id"
ad.Refresh
' refill grid
Call RereshGrid1(grid1, ad.Recordset)
grid1.Col = 0: grid1.TopRow = tmpsavedtoprow
grid1.Row = tmpsavedtoprow
Originally Posted by Calcu
Maybe you can hide the entire column? Grid.colhidden(1)=true
I tried it, it doesn't work.
but I still have a few questions. I will rephrase the previous questions as follows:
2 Question from Krool
1- I'll re-display the issue I explained earlier about the checkbox problem with the image below, is there a better solution than the one I suggested:'
Code:
'command3
Dim i3 As Integer
For i3 = 0 To grid1.Rows - 1
grid1.Col = 1
grid1.Row = i3
grid1.CellChecked = FlexNoCheckBox
Next
grid1.ColCheckBoxes(1) = False
2-Are there any options that I can use to quickly find the number of options that were checked and their rows values?
If I were to give an example of another method, for example, in the row selection method (by using the control or shift keys), I could get the number of selected rows, and the selected values ??as follows:
Code:
.
.
.
' Faster than having to go through the grid rows from beginning to end.
For i = 0 To grid1.SelectedRows - 1
c.Add grid1.TextMatrix(grid1.SelectedRow(i), 1)
Next
.
.
'Delete records by adodc and refill grid again
.
.
.
Originally Posted by Krool
How do you refresh the grid?
Because my grid must renumber the row after deleting one or more records and reinsert the data into the grid, I used this subroutine to refresh the grid.
Code:
Sub RereshGrid1(ByVal gr As VBFlexGrid, ByVal rs As Recordset)
Dim lngI As Long
Dim lngC As Long
lngC = rs.RecordCount
'gr.Redraw = False
gr.Visible = False ' maybe faster than redraw
gr.Clear
gr.Cols = 8
gr.Rows = 2
gr.FixedCols = 1
gr.FixedRows = 1
With gr
.TextMatrix(0, 0) = "columns name x"
.TextMatrix(0, 1) = "columns name x"
.TextMatrix(0, 2) = "columns name x"
.TextMatrix(0, 3) = "columns name x"
.TextMatrix(0, 4) = "columns name x"
.TextMatrix(0, 5) = "columns name x"
.TextMatrix(0, 6) = "columns name x"
.TextMatrix(0, 7) = "columns name x"
.ColWidth(0) = 700
.ColWidth(1) = 1200
.ColWidth(2) = 2200
.ColWidth(3) = 2200
.ColWidth(4) = 2200
.ColWidth(5) = 2800
.ColWidth(6) = 1200
.ColWidth(7) = 1200
.ColAlignment(0) = FlexAlignmentCenterCenter
.ColAlignment(1) = FlexAlignmentCenterCenter
.ColAlignment(2) = FlexAlignmentCenterCenter
.ColAlignment(3) = FlexAlignmentCenterCenter
.ColAlignment(4) = FlexAlignmentRightCenter
.ColAlignment(5) = FlexAlignmentCenterCenter
.ColAlignment(6) = FlexAlignmentLeftCenter
.ColAlignment(7) = FlexAlignmentCenterCenter
End With
If lngC Then
gr.Rows = 1
rs.MoveFirst
With rs
For lngI = 1 To lngC
gr.AddItem lngI & vbTab & .Fields("id") & vbTab & .Fields("data") & vbTab & .Fields("tepymelk") & vbTab & .Fields("nva") & vbTab & .Fields("khnames") & vbTab & .Fields("sen") & vbTab & .Fields("idkhab")
.MoveNext
Next lngI
End With
End If
gr.Visible = True
'gr.Redraw = True
End Sub
Point one: some fools still do not know the reason why cracked software should be used, companies or people who serve the terrorist or Zionist current must be fought, the current era is the era of soft war (the war of ideology and the battle of thoughts) is more important than hard war.
Point two: foolish thanks are worthless, I am here to shout out the faults so that they will be upset and stop their foolish pride, if you consider yourself strong, stop the death you are heading towards.
point third: some people or countries in the apocalypse era are just spectators, these are the most worthless creatures.
Point Four: NSA is one of the largest spy centers in the world : )) .
Point Five : Age is just a number, sometimes old people are stupider than young people.
-
Dec 12th, 2024, 01:31 AM
#1462
Addicted Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Hi, please make a new thread for this questions, it's not a bug, you will have more answers on the new topic, for sure.
-
Dec 12th, 2024, 02:30 AM
#1463
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Black_Storm,
you can use "virtual" checkboxes where you can erase them "instantly".
Below is a quick and dirty example. But you get the idea and you can adopt accordingly.
Code:
Private PropCheckboxes() As FlexCheckBoxConstants
Implements IVBFlexDataSource
Implements IVBFlexDataSource2
Private Sub CommandSetCheckboxes_Click()
ReDim PropCheckboxes(0 To VBFlexGrid1.Rows - 1) As FlexCheckBoxConstants
VBFlexGrid1.ColCheckBoxes(1) = True
Set VBFlexGrid1.FlexDataSource = Me
End Sub
Private Sub CommandClearCheckboxes_Click()
ReDim PropCheckboxes(0 To VBFlexGrid1.Rows - 1) As FlexCheckBoxConstants
VBFlexGrid1.Refresh
End Sub
Private Function IVBFlexDataSource_GetData(ByVal Field As Long, ByVal Record As Long) As String
'
End Function
Private Function IVBFlexDataSource_GetFieldCount() As Long
'
End Function
Private Function IVBFlexDataSource_GetFieldName(ByVal Field As Long) As String
'
End Function
Private Function IVBFlexDataSource_GetRecordCount() As Long
'
End Function
Private Sub IVBFlexDataSource_SetData(ByVal Field As Long, ByVal Record As Long, ByVal NewData As String)
'
End Sub
Private Function IVBFlexDataSource2_GetChecked(ByVal Field As Long, ByVal Record As Long) As Integer
If Field = 1 Then
IVBFlexDataSource2_GetChecked = PropCheckboxes(Record)
End If
End Function
Private Function IVBFlexDataSource2_GetFlags() As Long
IVBFlexDataSource2_GetFlags = FlexDataSourceNoData Or FlexDataSourceChecked
End Function
Private Function IVBFlexDataSource2_GetToolTipText(ByVal Field As Long, ByVal Record As Long) As String
'
End Function
Private Sub IVBFlexDataSource2_SetChecked(ByVal Field As Long, ByVal Record As Long, ByVal NewValue As Integer)
If Field = 1 Then
PropCheckboxes(Record) = NewValue
End If
End Sub
Private Sub IVBFlexDataSource2_SetToolTipText(ByVal Field As Long, ByVal Record As Long, ByVal NewValue As String)
'
End Sub
-
Dec 12th, 2024, 04:37 AM
#1464
Fanatic Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Okay krool, thanks, I'll work on that more.
-
Dec 13th, 2024, 04:51 AM
#1465
Fanatic Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Regarding checking checkboxes and clearing them and getting the count number of theme.
just 2 ways, which can definitely be better than this, maybe it will be useful for someone.
way 1 :
In this method, calculations need to be performed from the beginning to the end of the grid.
' for show checkboxes
Code:
grid1.ColCheckBoxes(1) = True
' for clear checkboxes fixed clear bug and there is no need refresh grid
Code:
Dim i3 As Integer
For i3 = 0 To grid1.Rows - 1
grid1.Col = 1
grid1.Row = i3
grid1.CellChecked = FlexNoCheckBox
Next
grid1.ColCheckBoxes(1) = False
' for get checked data
Code:
Dim c2 As New Collection, i2 As Integer
For i2 = 0 To grid1.Rows - 1
grid1.Col = 1 ' The column to be checked for the checkbox.
grid1.Row = i2
' Get the checked state of a checkbox from a previously defined row and column
If grid1.CellChecked = FlexChecked Then c2.Add grid1.Cell(FlexCellText)
Next
If c2.Count = 0 Then
Set c2 = Nothing
Exit Sub
End If
' c2 can use for process checked row
set c2 = nothing
way 2
improved speed for get checked count, get data checked and clear checkboxes:
' In this method, which requires more coding, there is no need to process the grid from beginning to end.
Code:
Private PropCheckboxes() As FlexCheckBoxConstants
Implements IVBFlexDataSource
Implements IVBFlexDataSource2
Dim datachecked As Collection
Public Function ColItemExists(ByVal oCol As Collection, ByVal vItem As Variant) As Boolean
Dim itm As Variant
Dim iIsObj As Boolean
iIsObj = IsObject(vItem)
For Each itm In oCol
If iIsObj Then
If IsObject(itm) Then
If itm Is vItem Then
ColItemExists = True
Exit Function
End If
End If
Else
If Not IsObject(itm) Then
If itm = vItem Then
ColItemExists = True
Exit Function
End If
End If
End If
Next
End Function
Private Sub Command1_Click()
Dim i As Integer
If Not datachecked Is Nothing Then
For i = 1 To datachecked.Count
'MsgBox datachecked(i)
MsgBox grid1.TextMatrix(datachecked(i), 1) ' ÇÑ áÇÒã ÏÇÔÊíã ÝíáÏ ÎÇÕí ÑÇ äãÇíÔ Ïåíã
Next
End If
End Sub
Private Sub CommandSetCheckboxes_Click()
ReDim PropCheckboxes(0 To grid1.Rows - 1) As FlexCheckBoxConstants
grid1.ColCheckBoxes(1) = True
Set grid1.FlexDataSource = Me
Set datachecked = New Collection
End Sub
Private Sub CommandClearCheckboxes_Click()
ReDim PropCheckboxes(0 To grid1.Rows - 1) As FlexCheckBoxConstants
grid1.ColCheckBoxes(1) = False
grid1.Refresh
Set datachecked = Nothing
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Set datachecked = Nothing
End Sub
Private Function IVBFlexDataSource_GetData(ByVal Field As Long, ByVal Record As Long) As String
' dont delete this function,its necessary
End Function
Private Function IVBFlexDataSource_GetFieldCount() As Long
' dont delete this function,its necessary
End Function
Private Function IVBFlexDataSource_GetFieldName(ByVal Field As Long) As String
' dont delete this function,its necessary
End Function
Private Function IVBFlexDataSource_GetRecordCount() As Long
' dont delete this function,its necessary
End Function
Private Sub IVBFlexDataSource_SetData(ByVal Field As Long, ByVal Record As Long, ByVal NewData As String)
' dont delete this sub,its necessary
End Sub
Private Function IVBFlexDataSource2_GetChecked(ByVal Field As Long, ByVal Record As Long) As Integer
If Field = 1 Then
IVBFlexDataSource2_GetChecked = PropCheckboxes(Record)
End If
End Function
Private Function IVBFlexDataSource2_GetFlags() As Long
IVBFlexDataSource2_GetFlags = FlexDataSourceNoData Or FlexDataSourceChecked
End Function
Private Function IVBFlexDataSource2_GetToolTipText(ByVal Field As Long, ByVal Record As Long) As String
' dont delete this function,its necessary
End Function
Private Sub IVBFlexDataSource2_SetChecked(ByVal Field As Long, ByVal Record As Long, ByVal NewValue As Integer)
If Field = 1 Then
PropCheckboxes(Record) = NewValue
If NewValue = 1 Then
If ColItemExists(datachecked, Str(Record + 1)) = False Then
datachecked.Add Str(Record + 1), CStr(Record + 1)
End If
Else
If ColItemExists(datachecked, Str(Record + 1)) = True Then
datachecked.Remove CStr(Record + 1)
End If
End If
End If
End Sub
Private Sub IVBFlexDataSource2_SetToolTipText(ByVal Field As Long, ByVal Record As Long, ByVal NewValue As String)
'
End Sub
krool ,I have a suggestion for such a problem, methods like the following are necessary.
Better clearing of checkboxes, while as I showed in the previous image, if the user clicks a checkbox and unchecks it again, the following method does not work correctly.
grid1.ColCheckBoxes(1) = False
add Something like this that doesn't require complex or long code.
Code:
For i = 1 To grid1.colcheckboxcount
grid1.colcheckboxed(i) ' or etc ...
Next
Originally Posted by Calcu
Hi, please make a new thread for this questions, it's not a bug, you will have more answers on the new topic, for sure.
hehe Hi again , how are youuuu mr xd xd and it is clear that it is a bug because it must be solved in a strange way, and I showed it in the previous image, just as Krool also provided a dirty example to solve this problem(according to his own words). Of course, I also showed a solution before, but the problem was speed and the lack of some methods, which I mentioned earlier and in this text. Don't even think about making a new thread , I was just kidding, good luck, maybe I'll see you next year .
Goodbye until another unknown time!
Point one: some fools still do not know the reason why cracked software should be used, companies or people who serve the terrorist or Zionist current must be fought, the current era is the era of soft war (the war of ideology and the battle of thoughts) is more important than hard war.
Point two: foolish thanks are worthless, I am here to shout out the faults so that they will be upset and stop their foolish pride, if you consider yourself strong, stop the death you are heading towards.
point third: some people or countries in the apocalypse era are just spectators, these are the most worthless creatures.
Point Four: NSA is one of the largest spy centers in the world : )) .
Point Five : Age is just a number, sometimes old people are stupider than young people.
-
Dec 13th, 2024, 05:00 AM
#1466
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
ColCheckBoxes is correcly working. It's not a bug, but a feature.
It certainly set's a flag on the column allowing for IVBFlexDataSource2 to execute GetChecked/SetChecked. (FlexDataSourceChecked must also be specified)
The other feature is that ColCheckBoxes translate any FlexNoCheckBox into FlexUnchecked. When ColCheckBoxes is false this "auto translation" is off. You can use FlexNoCheckBoxEver to avoid this kind of translation.
Another way would be to not use ColCheckBoxes at all and set the CellChecked manually on each row. Of course this is more time consuming as you need to "set all" and "clear all" in a loop.
EDIT:
You may also improve the loop by using code below instead of "CellChecked". This way you don't need to modify .Col and .Row which saves time.
Code:
VBFlexGrid1.Cell(FlexCellChecked, i3, 1) = FlexNoCheckBox
Last edited by Krool; Dec 13th, 2024 at 05:09 AM.
-
Dec 13th, 2024, 05:33 AM
#1467
Fanatic Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Krool
ColCheckBoxes is correcly working. It's not a bug, but a feature.
It certainly set's a flag on the column allowing for IVBFlexDataSource2 to execute GetChecked/SetChecked. (FlexDataSourceChecked must also be specified)
The other feature is that ColCheckBoxes translate any FlexNoCheckBox into FlexUnchecked. When ColCheckBoxes is false this "auto translation" is off. You can use FlexNoCheckBoxEver to avoid this kind of translation.
Another way would be to not use ColCheckBoxes at all and set the CellChecked manually on each row. Of course this is more time consuming as you need to "set all" and "clear all" in a loop.
EDIT:
You may also improve the loop by using code below instead of "CellChecked". This way you don't need to modify .Col and .Row which saves time.
Code:
VBFlexGrid1.Cell(FlexCellChecked, i3, 1) = FlexNoCheckBox
I did not talk about its features and other uses. My question was about the lack of methods and tools that can be used to quickly clear the grid with a method like grid1.ColCheckBoxes(1) = False or to get the number of checked items faster without having to scroll from the beginning to the end of the grid. As I mentioned before, the number of records may be large. And the things I mentioned before. In my opinion, the bug is the same implementation that I showed in the image or a method that does not work properly. The grid that I showed was not connected to any data at all. View the image again and see that the checkbox is checked and unchecked, and as you said, it is marked, and in the method grid1.ColCheckBoxes(1) = False because, for example, it is not cleared when marked. The fact that you give examples of its use in other places is useful in itself, but the nature of my question identifies the problem. If you have the opportunity and want to add changes or methods to the grid, consider these suggestions and do it yourself. You also mentioned that the speed of obtaining the checked values ??should be examined instead of checking from start to finish, which you also mentioned and I gave an example of at the beginning of the question in thread #1457.
I still think that there should be methods for checking the checked items, and the way you and I solved the problem and the examples you gave speak for themselves. Now that you insist that this is not a problem, it depends on you. I mentioned what was necessary. Good luck.
-
Dec 13th, 2024, 09:21 AM
#1468
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Black_Storm,
I am willing to listen and improve things when appropriate.
ColCheckboxes() is just a "flag". It doesn't set nor clear anything.
I am afraid you won't understand my point. But I hope you found the solution for your problem.
-
Jan 14th, 2025, 06:38 AM
#1469
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Excellent grid! Thank you Kroll!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|