Attachment 195693Attachment 195694
The foreground color is blended very well. Could you also blend the background? Thank you so much!
Printable View
Attachment 195693Attachment 195694
The foreground color is blended very well. Could you also blend the background? Thank you so much!
How should that work / look like ?
The cells with values 99.97, 99.96, and 99.98 have been marked with a pink background, but when I select an area that includes these cells, I cannot distinguish which cells have been highlighted with a pink background.
Add the UseBackColorSel property. When set to False, the color of the selected cell will be a blend of BackColor and SelBackColor.
fengzhongxia,
you can achieve what you need by a "workaround".
Continue to use .UseForeColorSel = False and then apply a 4x4 pixel solid color picture to a cell and set the .CellPictureAlignment = FlexPictureAlignmentStretch for fast "fill" of the background.
The picture is then effectively over the selected back color. See below example of the purple picture with a cyan fore color. Beneath a cell with red fore color and no custom background.
Attachment 195695
Only problem is when you still need a real picture in that cell. But this could also be circumvented when using ColImageList..
This method you've mentioned meets my requirements perfectly. Thank you so much, expert!
Update released.
Just noticed that in vsFlexGrid the cell "flooding" is not the whole cell background like here but has a padding in the size of the focus rect.
So the original cell back color or selected back color is still visible.
I kinda like this more and updated it now. That's also how it works in Excel with the solid bars.
Attachment 195698
Thinks!Very Good!
Hello Krool!
Thank you very much for providing the great VBCCR control.
1. The VBFlexGrid.ColPosition property is currently 'write-only'. Could it be changed to 'read/write'?
2. Is it possible to drag columns to a specified position (like 'ListView' or 'VSFlexGrid', allowing columns to be dragged to a specific position)? This would be more convenient because sometimes users need to adjust columns to their preferred positions.
3. If I want to click a column header to sort the column data in ascending or descending order, how should I set it up?
I hope to get your help, thank you very much!
1. The .ColPosition is indeed write-only. Will check it, thanks. But what's the reason you need to read it ? It's the same value as you input as index ? The vsFlexGrid and MSFlexGrid also are write-only.
2. Use the .DragCol function. Below a snippet which allows to re-arrange columns and rows when you press the alt key and left mouse button.
3. Use also the BeforeMouseDown event and set the .ColSortArrow and .ColSort properties and then you may use .Sort = FlexSortUseColSort for individual column sortings. You will figure it out for sure.Code:Private Sub VBFlexGrid1_BeforeMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single, Cancel As Boolean)
With VBFlexGrid1
If Button = vbLeftButton And (Shift And vbAltMask) = vbAltMask Then
.HitTest X, Y
If .HitResult = FlexHitResultCell Then
If .HitCol < .FixedCols And .HitRow >= .FixedRows Then
VBFlexGrid1.RowPosition(.HitRow) = VBFlexGrid1.DragRow(.HitRow)
Cancel = True
ElseIf .HitCol >= .FixedCols And .HitRow < .FixedRows Then
VBFlexGrid1.ColPosition(.HitCol) = VBFlexGrid1.DragCol(.HitCol)
Cancel = True
End If
End If
End If
End With
End Sub
You can also set .RowSortArrows if you have multiple fixed rows and want the sort arrows other than fixed row 0.
I want to say thank you to Krool because of this control (and the other ones), it is helping a lot in being able to program in VB6 in 2026.
All the new functions of this grid that allow editing are of great help.
VbFlexGrid supposrts CellOwnerDraw, like VBFlexGrid1.CellOwnerDraw(row, col) = True?
I asked CoPilot about the possibility of using different character styles in the same cell, as well as the possibility of using lowercase and uppercase letters, such as underlining or bold. CoPilot gave me this answer:
Excellent, Fabrizio — this is **your thing**: VB6, VBFlexGrid, owner-draw, total control of the cell.
I'll answer you in a **technical, empirical, and immediately operational** way, just the way you like it.
---
# ? How does `CellOwnerDraw(row, column) = True` work in VBFlexGrid
When you set:
```vb
VBFlexGrid1.CellOwnerDraw(row, column) = True
```
You're telling the control:
> "For this cell, **don't draw anything**.
> Call me in the `OwnerDrawCell` event and I'll do it."
This is a complete override of cell rendering.
---
# ? What you need to do after activating it
You need to handle the event:
```vb
Private Sub VBFlexGrid1_OwnerDrawCell(ByVal Row As Long, _
ByVal Col As Long, _
ByVal hDC As Long, _
ByVal Left As Long, _
ByVal Top As Long, _
ByVal Right As Long, _
ByVal Bottom As Long, _
ByVal DrawState As OwnerDrawStateConstants)
```
Here you have:
- the hDC to draw on
- the cell's rectangle
- the state (selected, focused, etc.)
And you can use any GDI API: `FillRect`, `TextOut`, `DrawText`, `BitBlt`, etc.
---
# ? Minimal and working example
Gray background and red text designs:
```vb
Private Sub VBFlexGrid1_OwnerDrawCell(Row As Long, Col As Long, _
hDC As Long, Left As Long, Top As Long, _
Right As Long, Bottom As Long, _
DrawState As OwnerDrawStateConstants)
Dim rc As RECT
rc.Left = Left
rc.Top = Top
rc.Right = Right
rc.Bottom = Bottom
' Background
FillRect hDC, rc, CreateSolidBrush(RGB(230, 230, 230))
' Text
SetTextColor hDC, RGB(200, 0, 0)
DrawText hDC, VBFlexGrid1.TextMatrix(Row, Col), -1, rc, DT_LEFT Or DT_VCENTER Or DT_SINGLELINE
End Sub
```
---
# ? Important Note
`CellOwnerDraw` must be set before the cell is drawn, so:
- in `Form_Load`
- or immediately after filling the grid
- or dynamically before a `Refresh`
---
# ? Want to do something more advanced?
I can help you:
- draw **icons** or **images** in the cell
- create **progress bars**, **badges**, **status indicators**
- manage **hover**, **selection**, **focus**
- implement **symmetric cell rendering** with centralized logic (in line with your style)
Tell me what you want to achieve and I'll prepare a clean, symmetric, and benchmark-safe code block.
That's all... CoPilot "guessed" that this was possible and pointed me to VbFlexGrid and the instructions on GitHub from Krool (!!!)
CoPilot evidently has a lot of imagination :D:D
Update released.
The drop-down calendar (FlexComboModeCalendar) will now resize upon WM_THEMECHANGED/WM_STYLECHANGED.
This allows to change theme/styles for the calendar on the EditSetupWindow event. (window created but not yet visible)
WM_THEMECHANGED for the obvious reason when someone dares to try to make a dark mode and needs the visual styles changed per code.
Or for the more common reason (WM_STYLECHANGED) when somebody needs to apply MCS_NOTODAY or so manually on the EditSetupWindow event.
Update released.
Usage of SetBkColor for the DrawFocusRect API so that it can work accurately.
This is especially visible when using dark mode colors. Just compare the focus rect below. Top is now after the update and bottom how it was before or is in a MSFlexGrid.
Attachment 196120
Dear Krol, an observation: By having the tabindex at 0 or another control (it can be commad Button, or another control) the DrawFocusRect property in the vbflexgrid disappears when the form is loaded..., however, componentone's FlexGrid does meet those characteristics.
Attachment 196173
When a form contains two tables, clicking the middle position between the two columns in the image causes the mouse cursor to jump immediately to the upper section.
When you click on the upper table, it scrolls up by a small amount; when you click on the lower table, it scrolls up by a large amount.
This issue does not occur when there is only one table in the form.
The problem disappears after setting the Windows display scale to 100%. How can I resolve this? Thank you very much!
VBFlexGridDemo
https://www.kdocs.cn/l/cdNXvTmjgRSE
Attachment 196185
This issue only occurs after moving the window to the position shown in the illustration and then clicking; it does not occur at the default window position.
When you include a new control "SplitContainer" you can not just blindly run the demo without checking the code.
For example. I changed "VBFlexGrid1" into "SplitContainer1" in the Form_Resize event and then the problems disappeared..
Code:Private Sub Form_Resize()
Dim Width As Single, Height As Single
Width = Me.ScaleWidth - SplitContainer1.Left - Me.ScaleX(8, vbPixels, Me.ScaleMode)
Height = Me.ScaleHeight - (PicturePanel.Height) - Me.ScaleY(8, vbPixels, Me.ScaleMode)
If Width > 0 Then SplitContainer1.Width = Width
If Height > 0 Then SplitContainer1.Height = Height
End Sub
Hi Krool, I need the old version of your VBFlexGrid.ctl user control because I’d like to release a portable version of the app I’m developing (a freeware interactive first-aid simulator). I’m unable to integrate the newer controls with DataBinding into the project. Where canJ find it? Thank in advance.
Thanks for your reply, sir. It should be an issue with the new control. I'll check it again.
Thanks Krool for your kind and prompt reply. I downloaded the set of files from GitHub and, after OLEGuids.tlb, integrated them into a new project in this order: 2 .bas > 2.cls > .CT; then saved and closed VB6. But if I try to launch the app, even without any VBgrid, or if I try to draw one on the form, I alwayes get an error at this point:
Private PropDataSource As MSDATASRC.DataSource, PropDataMember As MSDATASRC.DataMember, PropRecordset As Object
Asking the AI "WHY?", its answer is: to fix this issue use the oldest version, without DataBinding, of Krool User Control (I use the simplest functions of your grid).
Ok, you got an AI answer and that mislead me..
So, either make a reference to msdatsrc.tlb that is in C:\Windows\SysWOW64
Or set the compilation constant ImplementDataSource to False in the .ctl file.
Code:#Const ImplementDataSource = False ' True = Required: msdatsrc.tlb
Dear Krool,
I solved all problems doing with VB6.0 a new GRID User Control which meets my needs. It's light but enough powerfull for any simple app.
Thanks for you kindness and for your valuable contribution to community