Jump to content

Custom Index on a control


Recommended Posts

Hello all, 

I am running a fully data driven form with 2 list views. Is it possible to force my primary key from the database into the index of the listviews?

This would save me from having to create an array of the items and storing the PK for later referencing. I thought about adding another column to my listviews, but that is unnecessary data on the list and I don't really need the users seeing the ID's. 

My search methods could be weak, but I have searched for this and not come up with much other than, returning the index, not setting the index.

Thanks!

Link to comment
Share on other sites

  • Moderators

JakeJohnson74,

Just add the data to the ListView but use _GUICtrlListView_HideColumn to (guess what) hide the column. You may have to make the header unresponsive to prevent the users dragging the separators - like this:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <HeaderConstants.au3>

; The 0-based column to be disabled
Global $iFix_Col

_Main()

Func _Main()
    Local Const $hGUI = GUICreate("ListView Fix Column Width", 400, 300)

    Local Const $hListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 2, 2, 394, 268)

    _GUICtrlListView_HideColumn($hListView, 1) ; Hide column 1

    GUISetState(@SW_SHOWNORMAL)

    ; Prevent resizing of column 1
    $iFix_Col = 1

    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam

    ; Get details of message
    Local Const $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)

    ; Look for header resize code
    Local Const $iCode = DllStructGetData($tNMHEADER, "Code")

    Switch $iCode
        Case $HDN_BEGINTRACKW
            ; Now get column being resized
            Local $iCol = DllStructGetData($tNMHEADER, "Item")

            If $iCol = $iFix_Col Then
                ; Prevent resizing
                Return True
            Else
                ; Allow resizing
                Return False
            EndIf
    EndSwitch
EndFunc   ;==>_WM_NOTIFY

 I hope that helps.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...