Click here to Skip to main content
15,888,303 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to select 1 row with 2 items from listbox to use them in method


here i add 2 items in 1 row

C#
Uniqueslist.Items.Add(string.Format("{0} , {1}", MobIDTextUnq.Text, MobCntTextUnq.Text));


and i want to use this 2 items in this method

C#
public static void Loadmonster(int MobID,int Cont)
{
    DateTime time = System.DateTime.Now;
    time.ToLongTimeString();

    try
    {
        Packet packet = new Packet((ushort)Opcode.CLIENT_OPCODES.CLIENT_GM, true); //GM command
        packet.WriteUInt8((byte)6); //Loadmonster
        packet.WriteUInt8((byte)0);
        packet.WriteUInt32(MobID); // ID . mobs 22519
        packet.WriteUInt8(Cont); //No. of mobs 1
        packet.WriteUInt8((byte)3); //static
        Agent.Send(packet);
        CodeWindow.Logs.Items.Add("[" + time + "] : Loadmonster Done.");
    }
}


i think it's by loop but i don't know how to do this and i want if this like exmple 1 row selected never select it again and select the next row and never back again i hope someone help me with this problem .
[1]: http://i.stack.imgur.com/sjKgt.png

What I have tried:

but it's give me error under .Split
C#
var jointString = UnqEventWindow.Uniqueslist.Items[0];
              var sections = jointString.Split(',');

              int mobId = int.Parse(sections[0].Trim());
              int count = int.Parse(sections[1].Trim());

              Codes.Loadmonster(mobId, count);
Posted
Updated 2-Sep-16 10:56am
v2
Comments
[no name] 2-Sep-16 13:27pm    
Get the list item, split the list item, convert the strings to integers, call your method with the result. Not sure what your actual question is or what the problem is since the "What I have tried" does not contain what you have tried.
C Amr Moneim 2-Sep-16 13:42pm    
i edit What I have tried check it now
[no name] 2-Sep-16 13:54pm    
Okay so now what is the problem?
C Amr Moneim 2-Sep-16 14:00pm    
this is my problem http://www13.0zz0.com/2016/09/02/20/497757348.png
[no name] 2-Sep-16 14:05pm    
No that is not a problem at all. That would appear to be a string that you might want to be a link to a picture. It is not a link and I can't see the picture.

1 solution

It assume that a comma is only used to separate fields. If this is not always the case, then the code would break.

By the way using text to get back the item, is the worst possible method to do this as it is very fragile. What would happen when the application get localized and you realize that not all countries use the same list item separator? And worst, if the separator is also valid in number (like thousand separator).

When displaying combined data like this, you should never decode text but you should keep the original information associated to the item.

By the way, in .NET is really easy to do since you can use custom objects for list box items. You only need to override ToString() to provide desired display (or you might have a custom property for that purpose and tell the list box which property to use. Then it is trivial to convert say SelectedItem back to the original object type and then get desired information from that.

As soon as an item is not a single string from the start, you should use a custom class to represent items.

By the way, you should try to show your problem in text. And use hyperlinks. Don't expect user to cut and paste URL.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900