Jump to content

How do I do this with a list?


rcmaehl
 Share

Recommended Posts

Okay. I'm making a D&D program but I don't know how to implement item dropping/editing. So far I have:

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
Global $Msg, $Inv, $Act, $IID, $ToF, $IDo, $Val
Global $Menu[1], $Item[2], $Info[9], $Stat[9], $ModT[9], $ModN[9]
$Val = 000
GUI()
Func GUI()
; OCDed here a bit. Sorry! It was just bugging me a lot.
GUICreate("D&D Program"       , 400, 400, -01, -01, 0x80C10280)
$Menu[0] = GUICtrlCreateMenu("File")
$Item[0] = GUICtrlCreateMenuItem("Save", $Menu[0])
GUICtrlCreateMenuItem("", $Menu[0])
$Item[1] = GUICtrlCreateMenuItem("Exit", $Menu[0])
GUICtrlCreateTab(                 000, 000, 400, 380, 0x00000000)
; New Tab. Tab Contains Image, Details, and Stats of Character.
GUICtrlCreateTabItem("Profile")
; Static Controls
GUICtrlCreateGroup("Character"   , 010, 030, 230, 345, 0x00000000)
GUICtrlCreateLabel("Name"       , 020, 050, 201, 020, 0x00000000)
GUICtrlCreateLabel("Class"     , 020, 100, 100, 020, 0x00000000)
GUICtrlCreateLabel("Race"       , 130, 100, 100, 020, 0x00000000)
GUICtrlCreateLabel("Alignment"   , 020, 150, 100, 020, 0x00000000)
GUICtrlCreateLabel("Gold Peices" , 130, 150, 100, 020, 0x00000000)
GUICtrlCreateLabel("Lvl."       , 020, 200, 030, 020, 0x00000000)
GUICtrlCreateLabel("Exp."       , 060, 200, 060, 020, 0x00000000)
GUICtrlCreateLabel(""           , 130, 200, 100, 020, 0x00000000)
GUICtrlCreateLabel("Background"  , 020, 250, 210, 020, 0x00000000)
GUICtrlCreateGroup("Statistics"  , 245, 160, 150, 215, 0x00000000)
GUICtrlCreateLabel("B"         , 320, 170, 030, 020, 0x00000201); B Stands for Base
GUICtrlCreateLabel("M"         , 360, 170, 030, 020, 0x00000201); M Stands for Modifier
GUICtrlCreateLabel("Strength"    , 255, 190, 060, 020, 0x00000200)
GUICtrlCreateLabel("Dexterity"   , 255, 210, 060, 020, 0x00000200)
GUICtrlCreateLabel("Constitution", 255, 230, 060, 020, 0x00000200)
GUICtrlCreateLabel("Intelligence", 255, 250, 060, 020, 0x00000200)
GUICtrlCreateLabel("Wisdom"   , 255, 270, 060, 020, 0x00000200)
GUICtrlCreateLabel("Charisma"    , 255, 290, 060, 020, 0x00000200)
GUICtrlCreateLabel("Fortitue"    , 255, 310, 060, 020, 0x00000200)
GUICtrlCreateLabel("Reflex"   , 255, 330, 060, 020, 0x00000200)
GUICtrlCreateLabel("Will"       , 255, 350, 060, 020, 0x00000200)
; Dynamic Controls
$Info[0] = GUICtrlCreateInput("" , 020, 070, 210, 020, 0x00000000)
$Info[1] = GUICtrlCreateInput("" , 020, 120, 100, 020, 0x00000000)
$Info[2] = GUICtrlCreateInput("" , 130, 120, 100, 020, 0x00000000)
$Info[3] = GUICtrlCreateInput("" , 020, 170, 100, 020, 0x00000000)
$Info[4] = GUICtrlCreateInput("0", 130, 170, 100, 020, 0x00002000)
$Info[5] = GUICtrlCreateInput("0", 020, 220, 030, 020, 0x00002000)
$Info[6] = GUICtrlCreateInput("0", 060, 220, 060, 020, 0x00002000)
$Info[7] = GUICtrlCreateProgress(  130, 220, 100, 020, 0x00000000)
$Info[8] = GUICtrlCreateInput("" , 020, 270, 210, 100, 0x00001044)
$Stat[0] = GUICtrlCreateInput("0", 320, 190, 030, 020, 0x00002201)
$ModT[0] = GUICtrlCreateLabel("+", 350, 190, 010, 020, 0x00000201)
$ModN[0] = GUICtrlCreateInput("0", 360, 190, 030, 020, 0x00002201)
$Stat[1] = GUICtrlCreateInput("0", 320, 210, 030, 020, 0x00002201)
$ModT[1] = GUICtrlCreateLabel("+", 350, 210, 010, 020, 0x00000201)
$ModN[1] = GUICtrlCreateInput("0", 360, 210, 030, 020, 0x00002201)
$Stat[2] = GUICtrlCreateInput("0", 320, 230, 030, 020, 0x00002201)
$ModT[2] = GUICtrlCreateLabel("+", 350, 230, 010, 020, 0x00000201)
$ModN[2] = GUICtrlCreateInput("0", 360, 230, 030, 020, 0x00002201)
$Stat[3] = GUICtrlCreateInput("0", 320, 250, 030, 020, 0x00002201)
$ModT[3] = GUICtrlCreateLabel("+", 350, 250, 010, 020, 0x00000201)
$ModN[3] = GUICtrlCreateInput("0", 360, 250, 030, 020, 0x00002201)
$Stat[4] = GUICtrlCreateInput("0", 320, 270, 030, 020, 0x00002201)
$ModT[4] = GUICtrlCreateLabel("+", 350, 270, 010, 020, 0x00000201)
$ModN[4] = GUICtrlCreateInput("0", 360, 270, 030, 020, 0x00002201)
$Stat[5] = GUICtrlCreateInput("0", 320, 290, 030, 020, 0x00002201)
$ModT[5] = GUICtrlCreateLabel("+", 350, 290, 010, 020, 0x00000201)
$ModN[5] = GUICtrlCreateInput("0", 360, 290, 030, 020, 0x00002201)
$Stat[6] = GUICtrlCreateInput("0", 320, 310, 030, 020, 0x00002201)
$ModT[6] = GUICtrlCreateLabel("+", 350, 310, 010, 020, 0x00000201)
$ModN[6] = GUICtrlCreateInput("0", 360, 310, 030, 020, 0x00002201)
$Stat[7] = GUICtrlCreateInput("0", 320, 330, 030, 020, 0x00002201)
$ModT[7] = GUICtrlCreateLabel("+", 350, 330, 010, 020, 0x00000201)
$ModN[7] = GUICtrlCreateInput("0", 360, 330, 030, 020, 0x00002201)
$Stat[8] = GUICtrlCreateInput("0", 320, 350, 030, 020, 0x00002201)
$ModT[8] = GUICtrlCreateLabel("+", 350, 350, 010, 020, 0x00000201)
$ModN[8] = GUICtrlCreateInput("0", 360, 350, 030, 020, 0x00002201)
; New Tab. Tab contains character inventory displayed in a list.
GUICtrlCreateTabItem("Inventory")
$Inv = GUICtrlCreateListView(""  , 010, 030, 380, 300, 0x00000000)
_GUICtrlListView_AddColumn($Inv, "#"       , 040,     0x00000002)
_GUICtrlListView_AddColumn($Inv, "Item"    , 335                 )
$Act = GUICtrlCreateLabel(""     , 010, 345, 050, 020, 0x00000201)
$IID = GUICtrlCreateInput(""     , 060, 345, 200, 020, 0x00000201)
$ToF = GUICtrlCreateLabel(""     , 260, 345, 080, 020, 0x00000201)
$IDo = GUICtrlCreateButton("OK"  , 350, 345, 040, 020, 0x00000000)
GUICtrlCreateTabItem("Log")
GUICtrlCreateTabItem("Dice")
GUICtrlSetData($Act, "Add a(n)")
GUICtrlSetData($ToF, "To Inventory")
GUICtrlSetState($Stat[6], $GUI_HIDE)
GUICtrlSetState($Stat[7], $GUI_HIDE)
GUICtrlSetState($Stat[8], $GUI_HIDE)
GUISetState()
While 1
  $Msg = GUIGetMsg()
  GUICtrlSetData($Info[7], GUICtrlRead($Info[6])/10)
  Select
   Case $Msg = $GUI_EVENT_CLOSE or $Msg = $Item[1]
    Exit(0)
   Case $Msg = $ModT[0]
    If GUICtrlRead($ModT[0]) = "+" Then
     GUICtrlSetData($ModT[0], "-")
    Else
     GUICtrlSetData($ModT[0], "+")
    EndIf
   Case $Msg = $Act Or $Msg = $ToF
    If GUICtrlRead($Act) = "Add a(n)" Then
     GUICtrlSetData($Act, "Drop the")
     GUICtrlSetData($ToF, "From Inventory")
    Else
     GUICtrlSetData($Act, "Add a(n)")
     GUICtrlSetData($ToF, "To Inventory")
    EndIf
   Case $Msg = $Inv
    If GUICtrlRead($Act) = "Drop the" Then
     GUICtrlSetData($IID, _GUICtrlListView_GetSelectedColumn($Inv))
    EndIf
   Case $Msg = $IDo
    If GUICtrlRead($Act) = "Add a(n)" Then
     _GUICtrlListView_AddItem($Inv, $Val)
     _GUICtrlListView_AddSubItem($Inv, $Val, GUICtrlRead($IID), 1)
     $Val += 001
    Else
     ;_GUICtrlListView_DeleteItem($Inv,
    EndIf
   Case Else
    ;;;
  EndSelect
WEnd
EndFunc

I need a way to a "drop" items and have the list update.

Basically I need to have this:

# Item

0 Item 0

1 Item 1 <- Selected, and drop button pressed

2 Item 2

to become

# Item

0 Item 0

1 Item 2

I've searched the manuals but I can't figure out how to do this.

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

_GUICtrlListView_DeleteItemsSelected( will delete the selected item from the listview.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Will that update both columns?

EDIT: Doesn't work because the selected row is deselected when button is pressed, I think.

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

You could make a right click context menu to delete a single item, and have check boxes in the LV to select multiple items to be deleted.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You could make a right click context menu to delete a single item, and have check boxes in the LV to select multiple items to be deleted.

Is there any other methods I could use? I'm trying to figure out which one seems best for me.

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

Hope i understand what you want ! i could able to delete the selected items with function _GUICtrlListView_DeleteItemsSelected. Here is the sample code.. :graduated:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
$hGui = GUICreate("Test", 250, 250)
$hListView = GUICtrlCreateListView("Column 1|Column 2|Column 3", 5, 10, 240, 160)
$but = GUICtrlCreateButton("Delete",5,200,40,40)
For $i = 1 To 6
    GUICtrlCreateListViewItem("Item " & $i & "1|Item " & $i & "2|Item " & $i & "3", $hListView)
Next
GUISetState()
;GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
  Case $but
   _GUICtrlListView_DeleteItemsSelected($hListView)
  EndSwitch
WEnd

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

I gave up using a list view and went with a simple list for now. I couldn't get _GUICtrlListView_DeleteItemsSelected() to work, no matter how I used it. I just didn't delete anything.

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

Put this in place of your commented out code for the deletion of items in the code from your first post.

Else
         _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($Inv))
    EndIf

_GUICtrlListView_DeleteItemsSelected works when you pass it the handle of the Listview, but not the control ID.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Put this in place of your commented out code for the deletion of items in the code from your first post.

Else
         _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($Inv))
    EndIf

_GUICtrlListView_DeleteItemsSelected works when you pass it the handle of the Listview, but not the control ID.

Yes i knew that, but look at the @Syed23 example... :S ....that is strange. It uses the ControlID

Link to comment
Share on other sites

Syed23 used GUICtrlListViewAddItem while rcmaehl used _GUICtrlListView_AddItem that is the difference. I probably should have explained myself clearer when I posted what I did, so that was a failure on my part.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...