Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Grid Row Selection Behavior
#1
Hi Gintaras,
Thanks for your responses in Bug Reports.
Anyway, I hope you can help with this. I would like to multi-select rows in a grid without using Ctrl to add-to-selection or Shift to extend-selection.
Rather, single left click on any row: if not already selected, then adds to multi-select. If already selected, then unselects that row.
This is kind of how the Windows Explorer works if you hover over the "invisible" check box to the left side of each row. However, if you click on the item itself (farther to the left in the row), it behaves in standard fashion.

I think the problem is that on LMB down, it will always change the single selected item unless ctrl or shift already pressed.
I tried some with giving a simulated click but then I would need to test for already selected to un-select, etc.
I see from these two articles, that the solution may be harder than I thought:

http://www.c-sharpcorner.com/UploadFile ... DROW1.aspx
http://stackoverflow.com/questions/3915 ... ontrol-key

It would be great to have this more intuitive interface without having to have a hard to click check box row.
That reminds me that in this grid, the cells are not editable, so clicking anywhere on the row, causes select event.

Thanks again!!!,
S
#2
If the purpose is to get indices of selected items, better use check boxes and get checked items.
#3
SingleClick To MultiSelect DlgGrid Row

I played around with checkboxes as you suggested and then with hidden checkboxes, then without checkboxes at all, just using whether selected or not. I think this will work for me. Thanks for pointing me in the right direction!
Thanks!,
S


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


;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 QM_Grid 0x56031041 0x200 2 0 218 110 "0x13,0,0,0,0x840[]#,,7,[]Name,,7,"
;4 Button 0x54032000 0x0 16 114 48 14 "Get Selected"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030605 "" "" "" ""

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


ret
;messages
DlgGrid g.Init(hDlg 3)
sel message
,case WM_INITDIALOG
,_s=
,;1,A
,;2,B
,;3,C
,;4,D
,;5,E
,;6,F
,;7,G
,;8,H
,g.FromCsv(_s ",")
,ARRAY(int)+ arrintSelectedRows.create(g.RowsCountGet)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 4 ;;Get Selected
,,ARRAY(int) arrintGetSelectedRows
,,int TotSelectedRows = g.RowsSelectedGet(arrintGetSelectedRows)
,,out "Total Selected Rows = %i:" TotSelectedRows
,,for _i 0 arrintGetSelectedRows.len
,,,out arrintGetSelectedRows[_i]
,,act id(3 hDlg);;to make selected rows visible again

ret 1
;messages3
NMHDR* nh=+lParam
sel nh.idFrom
,case 3
,GRID.QM_NMLVDATA* cd=+nh
,NMLVDISPINFO* di=+nh
,NMLISTVIEW* nlv=+nh
,NMITEMACTIVATE* na=+nh
,sel nh.code
,,
,,;These notifications are from QM_Grid.
,,;All text coming from QM_Grid is in QM format (UTF-8 or ANSI, depending on QM Unicode mode).        
,,case [NM_CLICK,NM_DBLCLK,NM_RCLICK] ;;when user clicks a row or empty space, and it does not begin cell edit mode
,,,out "row click: %i %i" na.iItem na.iSubItem        
,,,
,,,if(arrintSelectedRows[na.iItem])
,,,,arrintSelectedRows[na.iItem] = 0
,,,else
,,,,arrintSelectedRows[na.iItem] = 1
,,,for _i 0 g.RowsCountGet
,,,,if(arrintSelectedRows[_i])
,,,,,g.RowSelect(_i 1)
#4
Hi Gintaras,
I am now trying to do this as you suggested with checkboxes. I would still like for the checkbox selection to cause the row to change background color. I tried using SendMessage LVM_SETBKCOLOR but it only changes the background of the checkbox instead of the entire row. So instead I used NM_CUSTOMDRAW as you suggested in http://www.quickmacros.com/forum/showthr...p?tid=2941

It works for coloring or uncoloring the background of all row cells but it paints all the rows you move over if you move the mouse too fast.

Any ideas how to implement NM_CUSTOMDRAW better?

Also, I would like to have multi-line text in a cell where all the text is visible (not just on hover over).
Like this:
   

Also is it possible to put in text button or icon/bmp button in the grid cell like this:

   

Thanks so much,
S


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


;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 133 "Dialog"
;3 QM_Grid 0x56031041 0x200 2 0 218 110 "0x33,0,0,0,0x80[]#,,7,[]Name,,7,"
;5 Button 0x54032000 0x0 4 114 100 16 "Get Checked"
;1 Button 0x54030001 0x4 116 114 48 14 "OK"
;2 Button 0x54030000 0x4 170 114 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030605 "" "" "" ""

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


ret
;messages
DlgGrid g.Init(hDlg 3)
sel message
,case WM_INITDIALOG
,_s=
,;1,A
,;2,B
,;3,C
,;4,D
,;5,E
,;6,F
,;7,G
,;8,H
,g.FromCsv(_s ",")
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 5 ;;Get Checked
,,ARRAY(int) arrintGetCheckedRows.redim        
,,int TotRows = g.RowsCountGet
,,int TotCheckedRows = 0
,,for _i 0 TotRows
,,,if(g.RowIsChecked(_i))
,,,,arrintGetCheckedRows[] = _i
,,,,TotCheckedRows = TotCheckedRows + 1
,,out "Total Checked Rows = %i:" TotCheckedRows
,,for _i 0 arrintGetCheckedRows.len
,,,out arrintGetCheckedRows[_i]

ret 1
;messages3
NMHDR* nh=+lParam
sel nh.idFrom
,case 3
,GRID.QM_NMLVDATA* cd=+nh
,NMLVDISPINFO* di=+nh
,NMLISTVIEW* nlv=+nh
,NMITEMACTIVATE* na=+nh
,NMLVCUSTOMDRAW* cd1=+nh
,int- CheckedRowBit
,sel nh.code        
,,;These notifications are from QM_Grid.
,,;All text coming from QM_Grid is in QM format (UTF-8 or ANSI, depending on QM Unicode mode).        
,,case [NM_CLICK,NM_DBLCLK,NM_RCLICK] ;;when user clicks a row or empty space, and it does not begin cell edit mode
,,,out "row click: %i %i" na.iItem na.iSubItem        
,,case LVN_ITEMCHANGED
,,,int row isChecked
,,,if(g.RowIsCheckNotification(lParam row isChecked)) out "%schecked %i" iif(isChecked "" "un") row
,,,,if(isChecked)
,,,,,CheckedRowBit = 1
,,,,else
,,,,,CheckedRowBit = 0
,,case NM_CUSTOMDRAW
,,,sel cd1.nmcd.dwDrawStage
,,,,case CDDS_PREPAINT ret DT_Ret(hDlg CDRF_NOTIFYITEMDRAW)
,,,,case CDDS_ITEMPREPAINT
,,,,,if(CheckedRowBit)
,,,,,,cd1.clrTextBk = 0xe0ff
,,,,,,g.RowSelect(-1)
,,,,,else
,,,,,,cd1.clrTextBk = 0xFFFFFF
,,,,,,g.RowSelect(-1)
#5
QM_Grid control does not support such buttons and images. Its purpose - simple text table display and editing.
#6
yes ok thanks for quick reply.

Any thoughts on better use of NM_CUSTOMDRAW for coloring entire on checkbox check and multiline text?

Re: more advanced Grid Controls like buttons, images, etc: I see around the forum using other other ActiveX grid controls in QM such as SCGrid or FlexGrid. I now understand the difference for what you made QMGrid vs a full-featured grid control like
http://www.exontrol.com/exgrid.jsp

Seems like a difficult thing for me but I hope to eventually learn how to incorporate something like that into my QM dialog, but for now will probably get along with the QM Grid functionality. But it seems like it should be able to do the coloring and multi-line text above as it is currently featured, right?
Most appreciated,
S
#7
Multiline text rows also not supported.
Now I'm working with a new QM version, don't want to play with NM_CUSTOMDRAW.
#8
I understand. Saves me time from trying to know that not possible/supported. Thanks and always look forward to new version of QM!,
S


Forum Jump:


Users browsing this thread: 1 Guest(s)