Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 04:32

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[help] c# listbox databinding not updating

Discussion on [help] c# listbox databinding not updating within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
clintonselke's Avatar
 
elite*gold: 0
Join Date: Feb 2007
Posts: 348
Received Thanks: 2,175
[help] c# listbox databinding not updating

Hi guys,

I'm new to c#... my first time, and hopefully not he last.

Just having trouble with listbox data-binding atm. For reasons I don't know, when changes are made to the data which the listbox is bounded to, the changes are not reflected inside the listbox.

The following is some of the code i'm using.

Firstly the intialisation and the bounding of the data to the listbox.
PHP Code:
        public MainForm()
        {
            
//
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            
InitializeComponent();
            
            
//
            // TODO: Add constructor code after the InitializeComponent() call.
            //
            
conquerProcesses = new ArrayList();
            
clientsListBox.DataSource conquerProcesses;
            
clientsListBox.DisplayMember "Name";
            
clientsListBox.ValueMember "Name";
        } 
As ya can see, i'm using the DataSource property to bound it to my list of running conquer online processes.

And this process list is updated by a timer object which triggers the following code 10 times per second.

PHP Code:
        void Timer1Tick(object senderEventArgs e)
        {
            
Process[] processList Process.GetProcessesByName("Conquer");
            foreach (
Process process in processList)
            {
                
//if (!clientsListBox.Items.Contains(process))
                //    clientsListBox.Items.Add(process);
                
bool has false;
                foreach (
CConquerProcess process2 in conquerProcesses)
                {
                    if (
process2.id == process.Id)
                    {
                        
has true;
                        break;
                    }
                }
                if (!
has)
                {
                    
conquerProcesses.Add(new CConquerProcess(process));
                }
            }
            
ArrayList removeList = new ArrayList();
            foreach (
CConquerProcess process2 in conquerProcesses)
            {
                
bool has false;
                foreach (
Process process in processList)
                {
                    if (
process2.id == process.Id)
                    {
                        
has true;
                        break;
                    }
                }
                if (!
has)
                {
                    
removeList.Add(process2);
                }
            }
            foreach (
CConquerProcess process in removeList)
                
conquerProcesses.Remove(process);
            foreach (
CConquerProcess process in conquerProcesses)
                
process.Update();
        }
    } 
and the CConquerProcess::Update() method updates the names of the characters from the running list of the processes by using getters/setters for the "Name" property of which the listbox is bounded to.

This update of the "Name" property only happens if there has been a change in character name (the person DCs and logs in another character), and the Update() method is called for every conquer process 10 times per second.

PHP Code:
    public class CConquerProcess
    
{
        public 
int    id;
        public 
IntPtr handle;
        public 
IntPtr playerBase;
        public 
string lastName "";
        
        public 
CConquerProcess(Process process)
        {
            
id process.Id;
            
handle MainForm.OpenProcess(MainForm.PROCESS_ALL_ACCESSfalseid);
            
int tmp;
            
byte[] bytes = new byte[4];
            
MainForm.ReadProcessMemory(handle, (IntPtr)0x00691CA0bytes4out tmp);
            
playerBase = (IntPtr)(bytes[0] + ((int)bytes[1] << 8) + ((int)bytes[2] << 16) + ((int)bytes[3] << 24));
            
//MessageBox.Show(id.ToString(),"k");
            //Debug.WriteLine(id + " constructed.");
            
lastName Name;
        }
        
        ~
CConquerProcess()
        {
            
MainForm.CloseHandle(handle);
        }
        
        public 
void Update()
        {
            
int tmp;
            
byte[] bytes = new byte[4];
            
MainForm.ReadProcessMemory(handle, (IntPtr)((int)playerBase 0x10C), bytes4out tmp);
            
IntPtr nameAddr = (IntPtr)(bytes[0] + ((int)bytes[1] << 8) + ((int)bytes[2] << 16) + ((int)bytes[3] << 24));
            
MainForm.ReadProcessMemory(handle, (IntPtr)((int)playerBase 0x110), bytes4out tmp);
            
IntPtr nameAddr2 = (IntPtr)(bytes[0] + ((int)bytes[1] << 8) + ((int)bytes[2] << 16) + ((int)bytes[3] << 24));
            
int length = ((int)nameAddr2 - (int)nameAddr);
            
bytes = new byte[length];
            
MainForm.ReadProcessMemory(handlenameAddrbyteslengthout tmp);
            
string name "";
            for (
int i 0length; ++i)
                
name += (char)bytes[i];
            if (
lastName.CompareTo(name) != 0)
            {
                
Name name;
            }
        }
        
        public 
string Name
        
{
            
get
            
{
                return 
lastName;
            }
            
set
            
{
                
lastName value;
            }
        }            
    } 
when i check this inside Debugger.WriteLine() it seems to work fine... but for some reason the listbox is not updating when its bounded data changes. Which seems to work for others on google.

Any Ideas?

Thx in advance.
clintonselke is offline  
Thanks
1 User
Old 07/29/2009, 03:44   #2
 
elite*gold: 0
Join Date: May 2009
Posts: 98
Received Thanks: 30
Try using ListBox.Refresh(). The reason it is not updating is because the ListBox has no way of telling when the databinding has an item added.
high7 is offline  
Thanks
2 Users
Old 07/29/2009, 06:05   #3
 
clintonselke's Avatar
 
elite*gold: 0
Join Date: Feb 2007
Posts: 348
Received Thanks: 2,175
Quote:
Originally Posted by high7 View Post
Try using ListBox.Refresh(). The reason it is not updating is because the ListBox has no way of telling when the databinding has an item added.
Thanks high6, working now.

I chucked in the following in the end of my timer function.
PHP Code:
            clientsListBox.DataSource conquerProcesses;
            
clientsListBox.Refresh(); 
Which redraws all the elements all the time, which i think kinda defeats the purpose of data binding. But oh well.
clintonselke is offline  
Old 07/29/2009, 17:20   #4
 
unknownone's Avatar
 
elite*gold: 20
Join Date: Jun 2005
Posts: 1,013
Received Thanks: 381
You're supposed to derive a class from ListBox and override the RefreshItems() method to sync the list with your data source.
unknownone is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
[Frage]VB08 listbox
05/15/2010 - .NET Languages - 3 Replies
Hi, wollte fragen, wie man das aktuell angewählte Item umändert sprich: Listbox1.items = Metin2, WoW, 4 Story jetzt will ich WoW in Runescape verändern ohne das es die 2te Position verlässt! Wie mache ich das?? MfG Bestshocker
updating?
03/04/2010 - Runescape - 0 Replies
is there a way to like..edit some item.cfg and when player logs in the client automaticly will download update?
Updating.
01/18/2010 - CO2 Private Server - 23 Replies
I was just wondering what would be required to update a the CoFuture source to patch 5017, i have never done this and would be interested if someone could supply my with some information.
[VB]Mehrer Fenster in Listbox
01/02/2010 - .NET Languages - 0 Replies
Howdi, wollt mal fragen wie ich mehrere Fenster mit dem "fast" gleichen namen in eine Lisbox bekomme ? Die Fenster sehen so aus Sbot v1.51 Sbot v1.51 Ich würde diese fenster gerne in eine Listbox einlesen.
[Request] Selected Item in listbox
11/22/2008 - CO2 Private Server - 6 Replies
Ok so i've been working on my own Admin panel for a LOTF source and been working on the disconnect from a listbox option. foreach (DictionaryEntry DE in World.AllChars) { Character Charr = (Character)DE.Value; if (Charr.MyClient.Online) { listBox1.SelectedItem = listBox1.SelectedItem; Charr.MyClient.Drop(); return;



All times are GMT +1. The time now is 04:34.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.