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";
}
And this process list is updated by a timer object which triggers the following code 10 times per second.
PHP Code:
void Timer1Tick(object sender, EventArgs 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();
}
}
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_ACCESS, false, id);
int tmp;
byte[] bytes = new byte[4];
MainForm.ReadProcessMemory(handle, (IntPtr)0x00691CA0, bytes, 4, out 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), bytes, 4, out 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), bytes, 4, out 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(handle, nameAddr, bytes, length, out tmp);
string name = "";
for (int i = 0; i < length; ++i)
name += (char)bytes[i];
if (lastName.CompareTo(name) != 0)
{
Name = name;
}
}
public string Name
{
get
{
return lastName;
}
set
{
lastName = value;
}
}
}
Any Ideas?
Thx in advance.






