Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
qm_grid and ICsv
#1
Hi All
I am trying to do what seems to be a simple thing but I can not wrap my head around it.
I have a csv file with system names and ip's. I would like to populate a grid and when I click on the grid in the ip column to ping that ip

example cvs
computer name , ip
test1,192.168.0.1
tes21,192.168.0.2
test3,192.168.0.3

click on 192.168.0.1 and ping said ip

any help would be appreciated
#2
Function dialog_grid_ping_ip
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str qmg3x
if(!ShowDialog("dialog_grid_ping_ip" &dialog_grid_ping_ip &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 QM_Grid 0x56031041 0x0 0 0 224 114 "0x12,0,0,0,0x0[]Computer name,,,[]IP,,,"
;END DIALOG
;DIALOG EDITOR: "" 0x2030400 "*" "" ""

ret
;messages
sel message
,case WM_INITDIALOG goto gInit
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto gNotify
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
;_______________________

;gInit
str csv=
;test1,192.168.0.1
;tes21,192.168.0.2
;test3,192.168.0.3

ICsv- t_csv=CreateCsv(1)
t_csv.FromString(csv)
t_csv.ToQmGrid(id(3 hDlg))

ret
;_______________________

;gNotify
NMHDR* nh=+lParam
sel nh.idFrom
,case 3
,NMITEMACTIVATE* na=+nh
,sel nh.code
,,case NM_CLICK ;;when user clicks a row or empty space, and it does not begin cell edit mode
,,if(na.iItem<0) ret
,,;out "row click: %i %i" na.iItem na.iSubItem
,,str IP=t_csv.Cell(na.iItem 1)
,,mes IP
#3
Thanks that works. I have no idea what the following code does. I removed it and nothing broke. I had to remove controls in the other statement where it was used I just could not understand what it is suppose to be doing.
Code:
Copy      Help
str controls = "3"
str qmg3x
#4
Can remove, this code here not used, it was inserted by dialog editor. You could assign CSV string to the variable to load the CSV into the grid easier, but in your case it is not useful.
#5
I needed almost the exact same code for a macro, but I can't get the following working
  • When a cell is edited, it's font-color becomes red and font style becomes bold (only the cell not the whole row).
  • When the 'SAVE' button is clicked all goes back to blue and normal (with normal I mean, none-bold)

The grid is initially loaded with a blue courrier font, this I could do but the 2 things above I can not get right.

The code is almost exact the same as you have given I only changed:
- user can edit cells
- initial font type and color is changed
- added a button called 'SAVE' (when this button get's clicked everything reverts back to the initial style => blue, none-bold)

The slightly changed code below:

Function dialog_grid_ping_ip
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str qmg3x
if(!ShowDialog("dialog_grid_ping_ip" &dialog_grid_ping_ip &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 QM_Grid 0x56031041 0x0 0 0 224 114 "0x2,0,0,0,0x0[]Computer name,,,[]IP,,,"
;4 Button 0x54032000 0x0 68 116 48 14 "SAVE"
;END DIALOG
;DIALOG EDITOR: "" 0x203050C "*" "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG goto gInit
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto gNotify
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
;_______________________

;gInit

;; ======= BEGIN: INITIAL FONT SETTINGS
__Font-- f
f.Create("Courier New" 10 0)
f.SetDialogFont(hDlg "3")

int hlv=id(3 hDlg)
SendMessage hlv LVM_SETTEXTCOLOR 0 0xff0000
;; ======= END: INITIAL FONT SETTINGS

str csv=
;test1,192.168.0.1
;tes21,192.168.0.2
;test3,192.168.0.3

ICsv- t_csv=CreateCsv(1)
t_csv.FromString(csv)
t_csv.ToQmGrid(id(3 hDlg))

ret
;_______________________

;gNotify
NMHDR* nh=+lParam
sel nh.idFrom
,case 3
,NMITEMACTIVATE* na=+nh
,sel nh.code
,,case NM_CLICK ;;when user clicks a row or empty space, and it does not begin cell edit mode
,,if(na.iItem<0) ret
,,;out "row click: %i %i" na.iItem na.iSubItem
,,str IP=t_csv.Cell(na.iItem 1)
,,mes IP
#6
Function dialog_grid_cell_color
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str qmg3x
if(!ShowDialog("" &dialog_grid_cell_color &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 QM_Grid 0x56031041 0x0 0 0 224 114 "0x2,0,0,0,0x0[]Computer name,,,[]IP,,,"
;4 Button 0x54032000 0x0 68 116 48 14 "SAVE"
;END DIALOG
;DIALOG EDITOR: "" 0x203050C "*" "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG goto gInit
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto gNotify
ret
;messages2
ARRAY(POINT)- t_ed ;;edited cells
sel wParam
,case 4 ;;Save
,t_ed=0
,InvalidateRect id(3 hDlg) 0 1
,case IDOK
,case IDCANCEL
ret 1
;_______________________

;gInit

;;;======= BEGIN: INITIAL FONT SETTINGS
__Font-- f fBold
f.Create("Courier New" 10 0)
fBold.Create("" 0 1 0 f 4)
f.SetDialogFont(hDlg "3")

int hlv=id(3 hDlg)
SendMessage hlv LVM_SETTEXTCOLOR 0 0xff0000
SendMessage hlv CCM_SETVERSION 5 0
;;;======= END: INITIAL FONT SETTINGS

str csv=
;test1,192.168.0.1
;tes21,192.168.0.2
;test3,192.168.0.3

ICsv- t_csv=CreateCsv(1)
t_csv.FromString(csv)
t_csv.ToQmGrid(id(3 hDlg))

ret
;_______________________

;gNotify
int i
POINT p

NMHDR* nh=+lParam
sel nh.idFrom
,case 3
,GRID.QM_NMLVDATA* d=+nh
,NMLVDISPINFO* di=+nh
,NMLISTVIEW* nlv=+nh
,NMITEMACTIVATE* na=+nh
,sel nh.code
,,case GRID.LVN_QG_CHANGE ;;when user changes grid content
,,if(d.hctrl)
,,,out "text changed: item=%i, subitem=%i, text=%s, newtext=%s" d.item d.subitem d.txt _s.getwintext(d.hctrl)
,,,;add this cell to t_ed if does not exist
,,,p.x=d.subitem; p.y=d.item
,,,for(i 0 t_ed.len) if(!memcmp(&t_ed[i] &p 8)) break
,,,if(i=t_ed.len) t_ed[]=p
,,else out "grid changed" ;;eg row deleted
,,
,,case NM_CUSTOMDRAW goto gCustomDraw
ret
;_______________________

;gCustomDraw
NMCUSTOMDRAW* cd=+lParam
NMLVCUSTOMDRAW* cd2=+lParam
sel cd.dwDrawStage
,case CDDS_PREPAINT _i=CDRF_NOTIFYITEMDRAW ;;yes, notify me to draw items
,case CDDS_ITEMPREPAINT _i=CDRF_NOTIFYSUBITEMDRAW ;;draw subitems
,case CDDS_ITEMPREPAINT|CDDS_SUBITEM
,p.x=cd2.iSubItem; p.y=cd.dwItemSpec
,for(i 0 t_ed.len) if(!memcmp(&t_ed[i] &p 8)) break
,if(i<t_ed.len)
,,out "%i %i" p.x p.y
,,cd2.clrText=0xff ;;red
,,SelectObject cd.hdc fBold
,else
,,cd2.clrText=0xff0000
,,SelectObject cd.hdc f
,_i=CDRF_NEWFONT
ret DT_Ret(hDlg _i)
#7
Thank you!!!

edit:

Sorry, the code works but:
- when I modify something from the first column ("Computer name"), it sets the whole row red and bold.
- when I modify something from the second column "IP", it sets only the modified cell red and bold.

I tried to change the code so that if something is changed in the first column ("Computer name") , it sets only the modified cell to red and bold.
I did not succeed in changing the code correctly.
#8
Updated.
Need to reset default color and font.
I don't receive notifications about post edits, better create new post.
#9
Ok, I will.
Thank you very much for this!!!
#10
Sorry to kick this topic up but how:
  • Whole row: How can I make the whole row red when an cell in that row has been edited
  • Specific cell: How can I make a specific cell "red" when a cell has been edited, I want to target a specific cell by using it's cell indicator # , # (example: 0,2)

    To solve the above 2 questions I think I must add something here (directly after the "red" part):

    Function dialog_grid_cell_color
    Code:
    Copy      Help
    ,if(i<t_ed.len)
    ,,out "%i %i" p.x p.y        
    ,,cd2.clrText=0xff ;;red
    ,,SelectObject cd.hdc fBold


  • Replace content: How do I replace contents of the first cell with the character "*" when a cell has been edited
    [computername 1][ip-adress 1] => when the cell "ip-adress 1" has been edited, "computername 1" will be replaced with "*"
    [computername 2][ip-adress 2]
    [computername 3][ip-adress 3]
    ...etc...

To set the cell content to "*" I use this (but I do not declare "DlgGrid g.Init(hDlg 3)" at the top of my code, I do not know if this is correct):

Function dialog_grid_cell_color
Code:
Copy      Help
,for(i 0 t_ed.len) if(!memcmp(&t_ed[i] &p 8)) break
,if(i<t_ed.len)
,,out "%i %i" p.x p.y        
,,cd2.clrText=0xff ;;red
,,SelectObject cd.hdc fBold        
,,
,,;;---
,,DlgGrid g.Init(hDlg 3)
,,_s="*"
,,g.CellSet(0 0 _s)
,,;;----
#11
Function dialog_grid_cell_color2
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

;2-dim array for colors of all rows and cells: {row0 cell(0 0) cell(0 1)},{row1 cell(1 0) cell(1 1)}...
ARRAY(int)- a

str controls = "3"
str qmg3x
if(!ShowDialog("" &dialog_grid_cell_color2 &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 QM_Grid 0x56031041 0x0 0 0 224 114 "0x2,0,0,0,0x0[]Computer name,,,[]IP,,,"
;4 Button 0x54032000 0x0 68 116 48 14 "SAVE"
;5 Button 0x54032000 0x0 2 116 48 14 "Set color"
;END DIALOG
;DIALOG EDITOR: "" 0x2030605 "*" "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG goto gInit
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto gNotify
ret
;messages2
sel wParam
,case 4 ;;Save
,memset &a[0 0] 0 a.len*a.len(1)*sizeof(int) ;;set all elements 0
,InvalidateRect id(3 hDlg) 0 1 ;;redraw grid
,
,case 5 ;;Set color
,int redrawRow=2
,a[0 redrawRow]=0x8080 ;;row color
,a[2 redrawRow]=0x80 ;;cell color
,SendMessage id(3 hDlg) LVM_REDRAWITEMS redrawRow redrawRow
,
,case IDOK
,case IDCANCEL
ret 1
;_______________________

;gInit

;;;======= BEGIN: INITIAL FONT SETTINGS
__Font-- f fBold
f.Create("Courier New" 10 0)
fBold.Create("" 0 1 0 f 4)
f.SetDialogFont(hDlg "3")

int- defColor=0xff0000 ;;default color

int hlv=id(3 hDlg)
SendMessage hlv LVM_SETTEXTCOLOR 0 defColor
SendMessage hlv CCM_SETVERSION 5 0
;;;======= END: INITIAL FONT SETTINGS

str csv=
;test1,192.168.0.1
;tes21,192.168.0.2
;test3,192.168.0.3

ICsv- t_csv=CreateCsv(1)
t_csv.FromString(csv)
t_csv.ToQmGrid(id(3 hDlg))

a.create(t_csv.ColumnCount+1 t_csv.RowCount)

ret
;_______________________

;gNotify
NMHDR* nh=+lParam
DlgGrid g.Init(nh.hwndFrom)
sel nh.idFrom
,case 3
,GRID.QM_NMLVDATA* d=+nh
,NMLVDISPINFO* di=+nh
,NMLISTVIEW* nlv=+nh
,NMITEMACTIVATE* na=+nh
,sel nh.code
,,case GRID.LVN_QG_CHANGE ;;when user changes grid content
,,if(d.hctrl)
,,,out "text changed: item=%i, subitem=%i, text=%s, newtext=%s" d.item d.subitem d.txt _s.getwintext(d.hctrl)
,,,if(d.item>=a.len) a.redim(d.item+1) ;;if more rows added to grid, add to a too
,,,a[0 d.item]=0x8000 ;;set changed row color
,,,a[d.subitem+1 d.item]=0xff ;;set changed cell color
,,else ;;eg row deleted
,,,out "grid changed"
,,,_i=g.RowsCountGet; if(_i!=a.len) a.redim(_i)
,,
,,case LVN_ENDLABELEDIT ;;when ends cell edit mode
,,out "end edit: item=%i subitem=%i text=%s" di.item.iItem di.item.iSubItem di.item.pszText
,,if di.item.iItem
,,,g.CellSet(di.item.iItem 0 "*") ;;change first cell in the row to "*"
,,
,,case NM_CUSTOMDRAW goto gCustomDraw
ret
;_______________________

;gCustomDraw
NMCUSTOMDRAW* cd=+lParam
NMLVCUSTOMDRAW* cd2=+lParam
int R ;;the return value
int x(cd2.iSubItem+1) y(cd.dwItemSpec)
sel cd.dwDrawStage
,case CDDS_PREPAINT
,R=CDRF_NOTIFYITEMDRAW ;;notify to draw items
,
,case CDDS_ITEMPREPAINT ;;now draw item
,if y<a.len and a[0 y] ;;if this row changed
,,cd2.clrText=a[0 y]
,,SelectObject cd.hdc fBold
,else
,,cd2.clrText=defColor
,,SelectObject cd.hdc f
,R=CDRF_NEWFONT|CDRF_NOTIFYSUBITEMDRAW ;;change font and notify to draw subitems
,,
,case CDDS_ITEMPREPAINT|CDDS_SUBITEM ;;now draw subitem
,if(y<a.len and a[x y]) cd2.clrText=a[x y] ;;if this cell changed
,else if(a[0 y]) cd2.clrText=a[0 y] ;;color of row
,else cd2.clrText=defColor
,;R=CDRF_NEWFONT

ret DT_Ret(hDlg R)
#12
wow!

Thank you very very much!


Forum Jump:


Users browsing this thread: 1 Guest(s)