Author Topic: Example code on editable Listview  (Read 4099 times)

0 Members and 1 Guest are viewing this topic.

chrisc

  • Guest
Example code on editable Listview
« on: March 22, 2018, 11:03:04 AM »
Hello

Is there any example on editable listview?  which allow users to key in data like in a MS excel worksheet

i briefly checked thru' the samples and found only listviews which do not allow user to key in data

Arnold

  • Guest
Re: Example code on editable Listview
« Reply #1 on: March 22, 2018, 11:26:55 AM »
Hi Chris,

Listview is rather complicated as there are so many options. There are some more types and extra constants / functions and extra notification routines  necessary. Some programmers use an extra dll to achieve all the functionality.

Can you supply an example code (not fragment)? I would try to do it in OxygenBasic. (could take some time). But maybe Mike has also some code for a Listview available.

Roland

Mike Lobanovsky

  • Guest
Re: Example code on editable Listview
« Reply #2 on: March 22, 2018, 05:55:53 PM »
Sorry guys, no ready made solution from me this time. I'm aware of this functionality but I have always used a separate text box for input and/or editing. I find the in-place editing option too obtrusive and interfering with the control's main mission.

Arnold

  • Guest
Re: Example code on editable Listview
« Reply #3 on: April 10, 2018, 04:52:03 AM »
Hi Chris,

searching in Internet I found this site of David Hillard's ZeeGrid - Win32 Grid Control:
http://www.kycsepp.com/

ZeeGrid is an editable grid which is released as a 32-bit and a 64-bit DLL. There is also provided the documentation, unfortunately not many examples. But it could be interesting to experiment a little bit with the possibilities of ZeeGrid. There are no special functions required to interact with ZeeGrid, all actions are done using the SendMessage function.

I coded the Quick-Start example as a normal Windows app and as an app using MainWindow of winutil.inc. I only used the 32-bit dll, but the demo compiled as 64-bit exe should also work with the 64-bit dll. By adding or applying the provided messages of ZeeGrid.inc some experiments should already be possible with the demo.

Roland

Code: OxygenBasic
  1. $ filename "ZeeGrid_Demo2.exe"
  2.  
  3. 'uses rtl32
  4. 'uses rtl64
  5.  
  6. uses WinUtil
  7. uses zeegrid
  8.  
  9. #autodim off
  10.  
  11.  
  12. declare SUB FormatGrid(sys hg)
  13.  
  14. sys hInstance=inst
  15. sys hgridmod
  16. sys hgrid
  17.  
  18. MainWindow 500,400,WS_OVERLAPPEDWINDOW
  19.  
  20.  
  21. function WndProc(sys hwnd, uMsg, wParam, lParam) as sys callback
  22.  
  23.     select uMsg
  24.         case WM_CREATE
  25.             SetWindowText(hwnd, "ZeeGrid Demo")
  26.            
  27.             hgridmod=LoadLibrary("zeegrid.dll")
  28.             if not hgridmod then
  29.                MessageBox(hWnd,"Unable to load ZeeGrid.DLL","Error",MB_OK)
  30.                PostQuitMessage(0)
  31.             end if
  32.             'if you are here, then the DLL loaded successfully
  33.            hgrid=CreateWindowEx(0,"ZeeGrid","My First ZeeGrid",
  34.                                  WS_CHILD|WS_VISIBLE|WS_BORDER,
  35.                                  0,0,0,0,
  36.                                  hWnd, 0,hInstance,null)
  37.             SendMessage(hgrid,ZGM_DIMGRID,10,0)  'set the grid to have 10 columns instead of the default 5
  38.            FormatGrid(hgrid)
  39.  
  40.         case WM_SIZE
  41.             RECT rect
  42.             GetClientRect(hWnd,&rect)
  43.             MoveWindow(hgrid,0,0,rect.right, rect.bottom\2,TRUE)  'Note: \ instead of /
  44.    
  45.         case WM_CLOSE
  46.             DestroyWindow(hwnd)
  47.        
  48.         case WM_DESTROY
  49.             PostQuitMessage(0)
  50.        
  51.         case else
  52.             return DefWindowProc(hwnd, uMsg, wParam, lParam)
  53.            
  54.     end select
  55.    
  56.     return 0
  57. end function
  58.  
  59.  
  60. =================================================
  61.  
  62. sub FormatGrid(sys hg)
  63.     SendMessage(hg,ZGM_SHOWROWNUMBERS,TRUE,0)
  64.     'create 5 rows of empty cells
  65.    int j
  66.     for j=1 to 5
  67.         SendMessage(hg,ZGM_APPENDROW,0,0)
  68.     next
  69.    
  70.     'set column header titles
  71.    SendMessage(hg,ZGM_SETCELLTEXT,1, "First" cr "Column")
  72.     SendMessage(hg,ZGM_SETCELLTEXT,2, "Second" cr "Column")
  73.     SendMessage(hg,ZGM_SETCELLTEXT,3, "Third" cr "Column")
  74.     SendMessage(hg,ZGM_SETCELLTEXT,4, "Fourth" cr "Column")
  75.     SendMessage(hg,ZGM_SETCELLTEXT,5, "Fifth" cr "Column")
  76.     SendMessage(hg,ZGM_SETCELLTEXT,6, "Sixth" cr "Column")
  77.     SendMessage(hg,ZGM_SETCELLTEXT,7, "Seventh Column is wide")
  78.     SendMessage(hg,ZGM_SETCELLTEXT,8, "Eighth" cr "Column")
  79.     SendMessage(hg,ZGM_SETCELLTEXT,9, "Ninth" cr "Column")
  80.     SendMessage(hg,ZGM_SETCELLTEXT,10,"Tenth" cr "and" cr "last" cr "Column")
  81.  
  82.     'make column 3 editable by the user
  83.    SendMessage(hg,ZGM_SETCOLEDIT,3,1)
  84.  
  85.     'auto size all columns
  86.    SendMessage(hg,ZGM_AUTOSIZE_ALL_COLUMNS,0,0)
  87. end sub
  88.  


Arnold

  • Guest
Re: Example code on editable Listview
« Reply #4 on: April 10, 2018, 05:53:04 AM »
I found this code for the grid control of James Klutho:
http://www.planetsquires.com/protect/forum/index.php?topic=4033.0

I succeeded in compiling the demos with Freebasic 1.05 and the results are really impressive. Unfortunately I do not know enough about Freebasic to create a DLL of the include file. Would this be possible or has this already been done somewhere? Which steps have to be taken to create a working Dll?

Thank you for any help.

Roland
« Last Edit: April 12, 2018, 11:25:57 PM by Arnold »

chrisc

  • Guest
Re: Example code on editable Listview
« Reply #5 on: April 10, 2018, 08:10:22 AM »
Thanxx a lot Roland

i got it compile to 64bit, this is really good,  i hope i can add some colors to it and other stuff
such as context menu which i can right click to delete a row or copy a row.
 

Aurel

  • Guest
Re: Example code on editable Listview
« Reply #6 on: April 10, 2018, 10:44:05 AM »
I have this , work for me on win32
by the way I already present here this example

Code: [Select]
$ Filename "ListView.exe" ' o2
include "RTL32.inc"
include "awinh037.inc"
INT win,wx=0,wy=0,ww=600,wh=400,wstyle = WS_MINMAXSIZE
INT button0,b0ID=100,lvID=1000
win=SetWindow("GUI:ListView",wx,wy,ww,wh,0,wstyle)
'crete button-----------------------------------------------------------------------
button0 = SetButton(win,180,4,80,26,"Close (X)",0x50001000,0x200,b0ID)

'create ListView --------------------------------------------------------------------
INT lvControl = SetListView (win, 20, 60, 300 , 300 ,"ListView", 150, 0, 0x200, lvID)
'------------------------------------------------------------------------------------
Wait()  'message loop
'------------------------------------------------------------------------------------
'func main
Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback
SELECT hwnd
CASE win
Select wmsg
CASE WM_CLOSE
CloseWindow(win)
EndProgram
End Select
END SELECT
RETURN Default
END FUNCTION

there are functions with ListView which i use
ListView is let say good for meny things and one of them is well known AdressBook or similar .

structures:
Code: [Select]
INT _lvleft,_lvinit,LV_ITEM
% LVM_INSERTCOLUMN  = 4123
% LVM_INSERTITEM    = 4103
% LVM_SETITEM       = 4102

TYPE ListviewColumn
    cmask as int
    cfmt as int
    ccx as int
    cpszText as int
    ccchTextMax as int
    ciSubItem as int
END TYPE

TYPE ListviewItem
    mask as int
    iItem as int
    iSubItem as int
    state as int
    stateMask as int
    pszText as int
    cchTextMax as int
    iImage as int
    lParam as int
END TYPE

DIM LV_COLUMN as ListviewColumn
DIM LV_ITEM as ListviewItem

Code: [Select]
'create ListView ==============================================================================
Function SetListView (byval lvhwnd as int,byval _lvx as int,byval _lvy as int,byval _lvw as int ,byval _lvh as int,byval lvstring as string,byval lvcwidth as int,byval _lvflag as int,byval _ex as int,byval _cID as INT) As INT
print "F:listView"
  If _lvflag=0
   _lvflag = 1409351681
  End If
  hListView = CreateWindowEx(_ex,"SysListView32","",_lvflag,_lvx,_lvy,_lvw,_lvh,lvhwnd,_cID,0,0)
  LV_COLUMN.cmask       = 7 'LVCF_FMT|LVCF_TEXT|LVCF_WIDTH
  LV_COLUMN.cfmt        = 0 '  LVCFMT_LEFT
  LV_COLUMN.ccx         = lvcwidth
  LV_COLUMN.cpszText    = strptr(lvstring)
  LV_COLUMN.ccchTextMax = sizeof(lvstring)+1
  'LV_COLUMN.ciSubItem   = 0
  SendMessage(hListView, LVM_INSERTCOLUMN, 0, LV_COLUMN) ' listview insert column 4123
  'GetAsyncKeyState(VK_LBUTTON)
   UpdateWindow lvhwnd
  Function = hListView
End Function
'-------------------------------------------------------------------------------------
'add list view column  {AddLVC hwnd, pos, width , text, flag}
Function AddListViewColumn (byval _lvhandle as int,byval _lvpos as int,byval _lvcwidth as int,byval lvstring as string,byval _lvflag as INT) as INT
  LV_COLUMN.cmask = 7
  LV_COLUMN.cfmt  = 0
  LV_COLUMN.ccx   =_lvcwidth
  LV_COLUMN.cpszText = strptr(lvstring)
  SendMessage( _lvhandle, LVM_INSERTCOLUMN,_lvpos,LV_COLUMN)
End Function
'-----------------------------------------------------------------------------------.
'add listview item {AddLVI hwnd, pos, text, icon}
Function AddListViewItem (byval _lvhandle as int,byval _lvpos as int,byval lvstring as string,byval _lvicon as int) as int
  INT lvflag
  lvflag = 4097 '#LVIF_TEXT|#LVIF_DI_SETITEM
  If _lvicon
    lvflag = 3 '#LVIF_TEXT|#LVIF_IMAGE
  End If
  LV_ITEM.mask     = lvflag
  LV_ITEM.iItem    = _lvpos
  LV_ITEM.iSubItem = 0
  LV_ITEM.pszText  = strptr(lvstring)
  LV_ITEM.iImage   =_lvicon
  SendMessage(_lvhandle,LVM_INSERTITEM,0,LV_ITEM) 'list view insert item
End Function
'----------------------------------------------------------------------------------
'add list view sub item
Function AddListViewSubItem (byval _lvhandle as int,byval _lvpos as int,byval _lvsub as int,byval lvstring as string)as INT
  LV_ITEM.mask      = 4097    '#LVIF_TEXT|#LVIF_DI_SETITEM
  LV_ITEM.iItem     = _lvpos
  LV_ITEM.iSubItem  = _lvsub
  LV_ITEM.pszText   = strptr(lvstring)
  SendMessage(_lvhandle, LVM_SETITEM,0,LV_ITEM)
End Function

but Arnold GRID control is really cool ...  :)

chrisc

  • Guest
Re: Example code on editable Listview
« Reply #7 on: April 10, 2018, 12:40:38 PM »
Thanxx Aurel

but i was not able to compile your example, can you please upload the entire program?
i'm only a beginner programmer

Aurel

  • Guest
Re: Example code on editable Listview
« Reply #8 on: April 10, 2018, 01:24:57 PM »
Ahh sorry looks confusing
ListView is really complex control and require lot of things.
Well explained is on codeproject site:
https://www.codeproject.com/Articles/2890/Using-ListView-control-under-Win-API

I must study this little bit more .
Ok here is example code and include file in attachment
work with o2Progress.

Code: [Select]
$ Filename "ListView.exe" ' o2
include "RTL32.inc"
include "awinh037.inc"
INT win,wx=0,wy=0,ww=600,wh=400,wstyle = WS_MINMAXSIZE
INT button0,b0ID=100,listv,lvID=1000, col1,col2
win=SetWindow("GUI:ListView",wx,wy,ww,wh,0,wstyle)
'crete button-----------------------------------------------------------------------
button0 = SetButton(win,180,4,80,26,"Close (X)",0x50001000,0x200,b0ID)

'create ListView --------------------------------------------------------------------
listv = SetListView (win, 20, 60, 300 , 300 ,"COL:0", 150, 0, 0x200, lvID)
'add column
col1= AddListViewColumn (listv, 1, 150, "COL:1"  , 0)
'add [0] column items
'add listview item {AddLVI hwnd, pos, text, icon}
AddListViewItem (listv, 0, "item_0", 0)
AddListViewItem (listv, 1, "item_1", 0)
AddListViewItem (listv, 2, "item_2", 0)
AddListViewItem (listv, 3, "item_3", 0)
AddListViewItem (listv, 4, "item_4", 0)

'------------------------------------------------------------------------------------
Wait()  'message loop
'------------------------------------------------------------------------------------
'func main
Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback
SELECT hwnd
CASE win
Select wmsg
CASE WM_CLOSE
CloseWindow(win)
EndProgram
End Select
END SELECT
RETURN Default
END FUNCTION
« Last Edit: April 10, 2018, 01:34:19 PM by Aurel »

Aurel

  • Guest
Re: Example code on editable Listview
« Reply #9 on: April 10, 2018, 02:27:39 PM »
Now is little bit more

Code: [Select]
$ Filename "ListView.exe" ' o2
include "RTL32.inc"
include "awinh037.inc"
INT win,wx=200,wy=200,ww=600,wh=420,wstyle = WS_MINMAXSIZE
INT button0,b0ID=100,listv,lvID=1000, col1,col2
win=SetWindow("GUI:ListView",wx,wy,ww,wh,0,wstyle)
'crete button-----------------------------------------------------------------------
button0 = SetButton(win,180,4,80,26,"Close (X)",0x50001000,0x200,b0ID)

'create ListView --------------------------------------------------------------------
listv = SetListView (win, 20, 60, 306 , 300 ,"COL:0", 150, 0, 0x200, lvID)
SendMessage listv, 4150 ,0 , 32  ' extended style - full row select
'add column
col1= AddListViewColumn (listv, 1, 150, "COL:1"  , 0)
'add [0] column items
'add listview item {AddLVI hwnd, pos, text, icon}
AddListViewItem (listv, 0, "item_0", 0)
AddListViewItem (listv, 1, "item_1", 0)
AddListViewItem (listv, 2, "item_2", 0)
AddListViewItem (listv, 3, "item_3", 0)
AddListViewItem (listv, 4, "item_4", 0)
'add lv_sub_item
'AddListViewSubItem (lvhandle, lvpos, lvsub , lvstring )
AddListViewSubItem (listv, 0, 1, "sub_item_0")
AddListViewSubItem (listv, 1, 1, "sub_item_1")
AddListViewSubItem (listv, 2, 1, "sub_item_2")
AddListViewSubItem (listv, 3, 1, "sub_item_3")
AddListViewSubItem (listv, 4, 1, "sub_item_4")


'------------------------------------------------------------------------------------
Wait()  'message loop
'------------------------------------------------------------------------------------
'func main
Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback
SELECT hwnd
CASE win
Select wmsg
CASE WM_CLOSE
CloseWindow(win)
EndProgram
End Select
END SELECT
RETURN Default
END FUNCTION

chrisc

  • Guest
Re: Example code on editable Listview
« Reply #10 on: April 10, 2018, 03:13:58 PM »
Thanxx Aurel

Got it compiled but the listview is not editable?

JRS

  • Guest
Re: Example code on editable Listview
« Reply #11 on: April 10, 2018, 05:20:27 PM »
Quote
but the listview is not editable

They're List Views. Try using a grid control for editing tables.
« Last Edit: April 10, 2018, 05:39:59 PM by John »

Charles Pegge

  • Guest
Re: Example code on editable Listview
« Reply #12 on: April 10, 2018, 06:31:09 PM »
Quote
Unfortunately I do not know enough about Freebasic to create a DLL of the include file. Would this be possible or has this already been done somewhere? Which steps have to be taken to create a working Dll?

Hi Roland,

If you take a look at src/oxygen.bas; it will show you how to create a DLL in FreeBasic.

You need to add ctor() and dtor() functions

Also, note the extern block to prevent name-mangling on the export functions:

  #ifdef OS_MS
    Extern "Windows-MS"
  #else
    extern "C"
  #endif
...

Then to build the DLL:

fbc -dll x.bas
« Last Edit: April 10, 2018, 06:39:17 PM by Charles Pegge »

Arnold

  • Guest
Re: Example code on editable Listview
« Reply #13 on: April 11, 2018, 01:01:57 AM »
Hi Charles,

that is the information I was looking for. I searched at different places but I forgot to check OxygenBasic itself. There are examples in the \dll folder and in the help file of FB, however I did not understand the differences of the existing options. But I think I can see now what I am missing. Thanks again.

Roland

Charles Pegge

  • Guest
Re: Example code on editable Listview
« Reply #14 on: April 11, 2018, 02:15:08 AM »
Such essential treasure is well concealed. No wonder they are often grumpy in the FB forum :)