Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add Picture to MSFlexGrid Cell in QM
Hi Gintaras,
For certain tasks, I am using MSFlexGrid instead of QM's native QM_Grid and DlgGrid functionality because it allows for multi-line wrapped text in rows of variable height and the ability to apply Text/background color to cell (see attached image and example code below).
One thing I can't figure out how to do is apply images to a cell even though there are functions for it. I think it is limitation of my understanding of interface.
There are four potentially relevant functions:

MSFlexGridLib.MSFlexGrid xGrid.CellPicture 
?  CellPicture()   ;;Property
 Returns/sets an image to be displayed in the current cell or in a range of cells.

word  CellPictureAlignment()   ;;Property
 Returns/sets the alignment of pictures in a cell or range of selected cells. Not available at design time.

?  Picture()   ;;Property,  read-only
 Returns a picture of the FlexGrid control, suitable for printing, saving to disk, copying to the clipboard, or assigning to a different control.

int  PictureType()   ;;Property
 Returns/sets the type of picture that should be generated by the Picture property.   ;;Possible values: flexPictureColor flexPictureMonochrome

I tried doing something like:
xGrid.CellPicture = "$qm$\text.bmp"
xGrid.CellPicture = LoadPictureFile("$qm$\text.bmp" 0)
xGrid.CellPicture = LoadPictureFile("$qm$\text.bmp" 1)

but they all fail saying:
"Error in MsFlexGridDlg:  expected Picture"

so then I tried:

Picture pic._getfile("$my pictures$\test.jpg")
xGrid.CellPicture = pic

but it returned 
Error (RT) in MsFlexGridDlg:  0x80004002, No such interface supported.    ? 
for Picture pic.

I found this on stackoverflow for VB6 but doesn't really help:

Select All      Help
 With MSFlexGrid1
   .Row = 1
   .Col = 1
   .RowSel = 1
   .ColSel = 1
   .CellAlignment = flexAlignCenterCenter
   Set .CellPicture = LoadPicture("C:\My Pictures\Me.bmp")
   ' Alternatively:
   ' Set .CellPicture = LoadResPicture(MY_PROFILE_PIC_ID)
 End With

Any advice?

Function MsFlexGridDlg
Select All      Help
function# hDlg message wParam lParam
if(hDlg) goto messages

;0 "" 0x90C80AC8 0x0 0 0 461 271 "Dialog"
;3 ActiveX 0x54030000 0x0 0 0 368 192 "MSFlexGridLib.MSFlexGrid {6262D3A0-531B-11CF-91F6-C2863C385E30} data:E585A5D0AA4293D1A27487688334A52541D9E9297C0AC17CC416169478846C108A9AD1DEB75F40C804"
;DIALOG EDITOR: "" 0x2030605 "" "" "" ""

if(!ShowDialog("MsFlexGridDlg" &MsFlexGridDlg)) ret

;;copy MSFLXGRD.X.manifest and MSFLXGRD.OCX to $qm$ folder
typelib MSFlexGridLib "$qm$\MSFLXGRD.OCX"

sel message
,MSFlexGridLib.MSFlexGrid xGrid
,xGrid._getcontrol(id(3 hDlg))
,xGrid.CellTextStyle = 0    
,xGrid.FontBold = 1
,xGrid.cols = 4
,xGrid.rows = 5
,xGrid.ScrollBars = 0
,xGrid.WordWrap = 1        
,xGrid.RowHeight(2) = 600
,str FlexGridCSVColl=
,;2,3,abc def ghi jkl mnop qrs tuv wxyz,8,0,2000    
,xGrid.BackColorBkg = ColorFromRGB(0 0 255)    
,xGrid.BackColor =  ColorFromRGB(0 255 0)
,xGrid.BackColorFixed  =  ColorFromRGB(255 0 0)
,xGrid.ForeColorFixed = ColorFromRGB(255 255 0)

,;xGrid.RowSel = 2
,;xGrid.BackColorSel = ColorFromRGB(255 255 0)
,int i j
,ICsv FlexGridCSV=CreateCsv(1); FlexGridCSV.FromString(FlexGridCSVColl)    
,for i 0 FlexGridCSV.RowCount
,,xGrid.Row = val(FlexGridCSV.Cell(i 0))
,,xGrid.Col = val(FlexGridCSV.Cell(i 1))
,,out F"Row {val(FlexGridCSV.Cell(i 0))} Col {FlexGridCSV.Cell(i 1)}"
,,xGrid.TextMatrix(xGrid.Row xGrid.Col) = FlexGridCSV.Cell(i 2)
,,xGrid.CellFontSize = val(FlexGridCSV.Cell(i 3))
,,xGrid.CellAlignment = val(FlexGridCSV.Cell(i 4))
,,xGrid.ColWidth(xGrid.Col) = val(FlexGridCSV.Cell(i 5))
,,xGrid.CellTextStyle = 0
,,xGrid.CellFontBold = 1
,,if(xGrid.Row > 0 and xGrid.Row%2)
,,,for j 1 xGrid.Cols
,,,,xGrid.Col = j                
,,,,xGrid.CellBackColor = ColorFromRGB(255 255 0)

,case WM_COMMAND goto messages2
sel wParam
,case IDOK
ret 1

Attached Files Image(s)
Function MsFlexGridDlg
Select All      Help
,IPicture p=+LoadPictureFile("$qm$\il_qm.bmp" 1)
,;IDispatch o=xGrid
works perfectly, thanks!!!!,
Two quick questions:
I would prefer to use qmgrid - is it hard to add the functionality I showed above in msflexgrid (multiline text, adjustable rowheight, background color, etc). Not urgent because I have alternative inmsflexgrid. I guess there is no end to this type of functionality one could build but just wondering for wishlist.

On a related topic, I was reading more in QM help about COM function interfaces and IDispatch - most of it above my head but I was intrigued about the ability to execute VbsExec functions. I have learned so much from the QM script examples on the forum and in the archive. I know realize there are countless examples of cool things on sites like
For example when you search on flexgrid, you get code examples like:

Combining DBGrid & Combo

(I know this is something already in qmgrid (!) but it's just an example.

I imagine that with a little bit of help (future questions), I could integrate much useful functionality into my QM-built apps with use of VbsExec. I guess I should just go ahead at some point and become more fully capable in VisualStudio with direct VB but I am so comfortable in QM IDE and have developed such a large codebase and appreciate you and the forum members.
Thanks again for all you do.
VbsExec is sometimes useful for something simple, but it is not for dialogs.
QM grid control will not be developed more.
ok. I understand. Again, much appreciated.

Forum Jump:

Users browsing this thread: 1 Guest(s)