Shoutbox

Help with GetItemText - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Help with GetItemText (/showthread.php?tid=84839)

Help with GetItemText by SnuZZer on 07-15-2008 at 01:08 PM

Hey.

I'm making an website for quotes for my IRC channel. The idea is, that people can send in quotes, but I do of course not want everything quoted on the site, so my idea is to combine it with MSG Plus! When people have added a quote on the website, it shall be accepted or declined in MSG Plus!

My idea is to make a list control where all quotes appears and when I press the accept/decline button a webpage should popup where I'll run some PHP codes to update the MySQL database.

What I want is, that when you have chosen a quote on the list control and pressed the accept/decline button, I want to get the ID for the quote.
At the moment the ID shall only popup in a toast for further development.

I can't figure out how to get the ID.

Here's my code:

code:
function initializeWin()
{
    var LstQuotes = MsgPlus.CreateWnd("LstQuotes.xml", "Win");

    for(i=1;i<=5;i++)
    {
        var item = LstQuotes.LstView_AddItem("ListView", i);
        LstQuotes.LstView_SetItemText("ListView", item, 1, "Quote no. " + i);
    }
}

function OnWinEvent_CtrlClicked(Wnd, CtrlId)
{
    switch(CtrlId)
    {   
        case "BtnAccept":
        {
            MsgPlus.DisplayToast("WoWForge Quotes", "Test: " + LstQuotes.LstView_GetItemText("ListView", "DON'T KNOW WHAT VALUE I HAVE TO GIVE THIS", 0));
            break;
        }
    }
}

You can check the red line with the bolded text. Well, the text says it all. I think, I've made it right, but I don't know what value I have to put there.

The necessary part of my XML document:
code:
        <Control xsi:type="ListViewControl" Id="ListView">
            <Position Top="1" Width="350" Left="2" Height="100">
                <Anchor Horizontal="LeftRightFixed" Vertical="TopBottomFixed"/>
            </Position>
            <Attributes>
                <AutoTip>false</AutoTip>
                <AlwaysShowSelection>false</AlwaysShowSelection>
            </Attributes>

            <ReportView>
                <SortColHeader>true</SortColHeader>
            </ReportView>

            <Columns>
                <Column>
                    <ColumnId>No</ColumnId>
                    <Label>#</Label>
                    <Width>5</Width>
                </Column>
                <Column>
                    <ColumnId>Quote</ColumnId>
                    <Label>Quote</Label>
                    <Width>98</Width>
                </Column>
            </Columns>
        </Control>

                <Control xsi:type="ButtonControl" Id="BtnAccept">
                <Position Left="2" Top="104" Width="172" Height="15"/>
            <Caption>Accepter</Caption>
            </Control>

              <Control xsi:type="ButtonControl" Id="BtnDecline">
                     <Position Left="180" Top="104" Width="172" Height="15"/>
            <Caption>Afvis</Caption>
             </Control>

I've attached a picture, so it's easier for you to see, what I'm talking about. By ID, I mean the number in the #-row. That's what I want.

Thanks in advance
Simon Støvring
RE: Help with GetItemText by Matti on 07-15-2008 at 01:42 PM

You'll need to get the index of currently selected item in your ListView. Because ListViewControls support multi-selections (although you have to specify it in your XML to actually use this), you have to loop through all rows and see if that row is selected or not. If it is selected, you can use that index.

code:
//Loop from the first (index 0) to the last (index Count-1, Count is not included with the < operator) row in the list
for(var Index=0; Index < PlusWnd.LstView_GetCount("ListView"); Index++) {
   //If this item is selected...
   if(PlusWnd.LstView_GetSelectedState("ListView", Index) === true) {
      //Break out of the loop
      break;
   }
}
//Do something with Index, like
Debug.Trace("Selected item: "+PlusWnd.LstView_GetItemText("ListView", Index, 1));

RE: Help with GetItemText by SnuZZer on 07-15-2008 at 06:06 PM

Yay! Many thanks ;-)

That's problably not the last word, you've heard from me... 8-)