Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
changing 2D arrays to lpstr
#1
I have an array I require to display its content into QM Grid for that purpose I require you to tell how can I convert 2D array to lpstr.
#2
Macro Macro1534
Code:
Copy      Help
;create 2D array for testing
ARRAY(str) a.create(2 3)
a[0 0]="A"
a[1 0]="B"
a[0 1]="C"
a[1 1]="D"
a[0 2]="E"
a[1 2]="F"

;-------------

;create ICsv variable from the array
ICsv c=CreateCsv(1)
int i nc(a.len(1))
for(i 0 a.len) c.AddRowSA(i nc &a[0 i])

;ICsv -> grid control
c.ToQmGrid(id(1532 "Options")) ;;grid in QM Options dialog, Tools tab
;or
;DlgGrid g.Init(id(1532 "Options")); g.FromICsv(c)

;-------------

;if you need string
str s
c.ToString(s)
out s
#3
Thanks that's perfect.

One more problem I am using Qm Grid in my program, I want to allow the user to cells value but same time he should not be able to add/remove rows. I have switched on style for not allowing to add/remove rows. But still whenever I press Enter key it automatically inserts new row.
#4
Should not insert new row. Try this function, it does not add new row on Enter.

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

str controls = "3"
str qmg3x
qmg3x="A[]B"
if(!ShowDialog("Dialog95" &Dialog95 &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 98 "0x2,0,0,0,0x0[]A,,,[]B,,,"
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#5
True your code doesnot add rows on enter. I am providing my code please check and reply.

\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

#compile "qmgrid"

if(!ShowDialog("Confirm_Orders" &Confirm_Orders 0)) ret

BEGIN DIALOG
0 "" 0x90C80AC8 0x100 0 0 265 191 "Confirm Orders"
3 QM_Grid 0x56031041 0x0 0 0 264 162 "0x3,0,0,0,0x0[]"
4 Button 0x54032000 0x0 30 170 48 14 "Submit"
5 Button 0x54032000 0x0 192 170 48 14 "Cancel"
END DIALOG
DIALOG EDITOR: "" 0x2030208 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,int g=id(3 hDlg)
,;use first column as noneditable
,SendMessage g LVM_QG_SETSTYLE QG_NOEDITFIRSTCOLUMN -1
,;add columns
,LvAddCol g 0 "Scrip" 80
,LvAddCol g 1 "Quantity" 70
,LvAddCol g 2 "Sell Rate" 70
,LvAddCol g 3 "Stop Loss" 70
,LvAddCol g 4 "Trigger" 70
,;populate ICsv variable
,ICsv c=CreateCsv(1)
,ARRAY(str) orders
,orders.create(2 3)
,orders[0 1]="Hi"
,orders[0 2]="Hello"
,int i nc(orders.len(1))
,for(i 0 orders.len)
,,c.AddRowSA(i nc &orders[0 i])
,,out orders[0 i]
,c.ToQmGrid(g)
,out "ncols=%i, nrows=%i" c.ColumnCount c.RowCount
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,;get and show all cells
,c=CreateCsv; c.Separator=","
,c.FromQmGrid(id(3 hDlg))
,str s
,c.ToString(s)
,mes s
,
,case IDCANCEL
ret 1
;messages3
NMHDR* nh=+lParam
if(nh.idFrom=3) ret DT_Ret(hDlg gridNotify(nh))
#6
I did not try, but probably need to remove

SendMessage g LVM_QG_SETSTYLE QG_NOEDITFIRSTCOLUMN -1

In QM 2.3.2 all your code can be simplified, like in my previous post.
#7
Thanks it's fine now. I will be grateful if you can suggest changes for my code.
#8
1. Easier to add columns in dialog editor, unless you need to do it at run time.
2. ICsv variable not necessary.

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

if(!ShowDialog("Confirm_Orders" &Confirm_Orders 0)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x100 0 0 265 191 "Confirm Orders"
;3 QM_Grid 0x56031041 0x0 0 0 264 162 "0x3,0,0,0,0x0[]Scrip,80[]Quantity,70[]Sell Rate,70[]Stop Loss,70[]Trigger,70"
;4 Button 0x54032000 0x0 30 170 48 14 "Submit"
;5 Button 0x54032000 0x0 192 170 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030208 "" "" ""

ret
;messages
DlgGrid g.Init(hDlg 3)
sel message
,case WM_INITDIALOG
,ARRAY(str) orders
,orders.create(2 3)
,orders[0 1]="Hi"
,orders[0 2]="Hello"
,int i nc(orders.len(1))
,for(i 0 orders.len)
,,out orders[0 i]
,,g.RowAddSetSA(i &orders[0 i] nc)
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,;get and show all cells
,str s
,g.ToCsv(s ",")
,mes s
,
,case IDCANCEL
ret 1
;messages3
NMHDR* nh=+lParam
;if(nh.idFrom=3) ret DT_Ret(hDlg gridNotify(nh))
#9
One more problem grid display extra rows than data uploaded. How can I remove those extra lines. Also how can I control number of rows and columns through code.
#10
Extra rows cannot be removed. They are read-only.
You can use functions, like g.RowAddSetSA. Type g., doubleclick a function from the list, press F1 for help.


Forum Jump:


Users browsing this thread: 1 Guest(s)