在Pocket PC的编程应用程序上使用ListBox [英] using ListBox on programming application for pocket pc

查看:74
本文介绍了在Pocket PC的编程应用程序上使用ListBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
我的应用程序有问题.我从PC发送了一个string []到袖珍PC,然后在ListBox上显示了该string [].它表现得很完美.然后,我继续发送另一个string []到Pocket PC.我尝试使用

Hi all!
I have some problem with my application. I sent a string[] from PC to pocket pc and then show that string[] on a ListBox. It showed perfectly. Then I continued to send another string[] to pocket pc. I try to use

listBox.Items.Clear()

清除旧数据并显示新数据.但这没有用.我该怎么解决?
listBox.Items.Clear()在净CF中不起作用吗?

非常感谢!

是的!我将发布我的代码.似乎很长.我使用套接字在PC和PPC之间发送数据.这是PPC上的客户端:

to clear old data and show new data. But it didn''t work. How can I solve that?
Didn''t listBox.Items.Clear() work in net CF?

Thank you very much!

Yes! I will post my code. It seem quite long. I used socket to send data between PC and PPC.This is client on PPC:

<pre lang="msil">public partial class Form2 : Form
    {
        public Socket client_PCRemote;
        //IPEndPoint iep;
        EndPoint remote;
        public Form1 frm1;
        //private int serverPort = 2011;
        Thread receive = null;
        delegate void capnhatCT(string value);
        capnhatCT controlSet;
        public string path = null;
        public Form2()
        {
            InitializeComponent();
        }
        private void Form2_Load(object sender, EventArgs e)
        {
            remote = (EndPoint)client_PCRemote.RemoteEndPoint;
            receive = new Thread(new ThreadStart(receiveDt));
            receive.Start();
        }
        public void receiveDt()
        {
            while (true)
            {
                try
                {
                    //MessageBox.Show("co du lieu nhan");
                    byte[] data = new byte[1024 * 32];
                    int recv = client_PCRemote.ReceiveFrom(data, ref remote);
                    string response = Encoding.ASCII.GetString(data, 0, recv);
                    //response = response.TrimStart(tmp.ToCharArray());
                    string tmp;
                    if(response.Contains("disk"))
                    {
                        tmp = "disk";
                        response = response.TrimStart(tmp.ToCharArray());
                        string[] entry = response.Split(''\\'');
                        foreach(string entry1 in entry)
                        {
                            controlSet = new capnhatCT(UpdateCB);
                            if(this.comboBox1.InvokeRequired)
                            {
                                this.Invoke(controlSet, new object[] {entry1});
                            }
                        }
                    }
                    if (response.Contains("folder"))
                    {
                        ShowFolder(response);
                    }
                    if (response.Contains("subFolder"))
                    {
                        ShowSubFolder(response);
                    }
                }
                catch(Exception ex)
                {
                }
            }
        }
        private void ShowFolder(string a)
        {
            listBox1.Items.Clear();
            //I can''t show data to listbox if I use this
            listBox2.Items.Clear();
            //I can''t show data to listbox if I use this
            string idenString = "folder";
            a = a.TrimStart(idenString.ToCharArray());
            string[] tempalate = a.Split(''^'');
            string folder = tempalate[0];
            string file = tempalate[1];
            string[] fld_entry = folder.Split(''\\'');
            string[] file_entry = file.Split(''\\'');
            controlSet = new capnhatCT(UpdateLB);
            for (int i = 0; i < fld_entry.Length; i++)
            {
                if (this.listBox1.InvokeRequired)
                {
                    this.Invoke(controlSet,new object[] {fld_entry[i]});
                }
            }
            controlSet = new capnhatCT(UpdateLBFile);
            for (int i = 0; i < file_entry.Length; i++)
            {
                if (this.listBox2.InvokeRequired)
                {
                    this.Invoke(controlSet, new object[] { file_entry[i] });
                }
            }
        }
        private void ShowSubFolder(string a)
        {
            listBox1.Items.Clear();
            //it is the same
            listBox2.Items.Clear();
            //it is the same
            string idenString = "subFolder";
            a = a.TrimStart(idenString.ToCharArray());
            string[] tempalate = a.Split(''^'');
            string folder = tempalate[0];
            string file = tempalate[1];
            string[] fld_entry = folder.Split(''\\'');
            string[] file_entry = file.Split(''\\'');
            controlSet = new capnhatCT(UpdateLB);
            for (int i = 0; i < fld_entry.Length; i++)
            {
                if (this.listBox1.InvokeRequired)
                {
                    this.Invoke(controlSet, new object[] { fld_entry[i] });
                }
            }
            controlSet = new capnhatCT(UpdateLBFile);
            for (int i = 0; i < file_entry.Length; i++)
            {
                if (this.listBox2.InvokeRequired)
                {
                    this.Invoke(controlSet, new object[] { file_entry[i] });
                }
            }
        }
        public void UpdateCB(string value)
        {
            comboBox1.Items.Add(value);
        }
        public void UpdateLB(string value)
        {
            listBox1.Items.Add(value);
        }
        public void UpdateLBFile(string value)
        {
            listBox2.Items.Add(value);
        }
        public void sendRequest(string request)
        {
            try
            {
                byte[] data = new byte[1024 * 32];
                data = Encoding.ASCII.GetBytes(request);
                client_PCRemote.SendTo(data, remote);
            }
            catch (Exception ex) { }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            sendRequest("GetDisk");
        }
        private void menuItem2_Click(object sender, EventArgs e)
        {
            if (client_PCRemote != null)
            {
                client_PCRemote.Close();
            }
            if (receive != null)
            {
                receive.Abort();
            }
            frm1.Close();
            this.Close();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            string folder = comboBox1.SelectedItem.ToString();
            string tamp = "GetFolder" + folder;
            sendRequest(tamp);
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        private void menuItem3_Click(object sender, EventArgs e)
        {
            string name = listBox1.SelectedItem.ToString();
            string tmp_path = comboBox1.Text + "\\" + name;
            path = tmp_path;
            textBox1.Text = tmp_path;
            string send_string = "GetSubFolder" + tmp_path;
            sendRequest(send_string);
        }
        private void menuItem4_Click(object sender, EventArgs e)
        {
            string name = listBox2.SelectedItem.ToString();
            string temp = comboBox1.Text + "\\" + name;
            string send_string = "OpenFile" + temp;
            sendRequest(send_string);
        }
    }





推荐答案

很难说不看代码,但是我怀疑您已经创建了ListBox的new实例,而不是清除现有实例.

如果不是这种情况,那么我们将需要查看相关的代码片段.


是的,我在上面发布了我的代码.谢谢".

这样更清楚了!
答案在您的代码中:

Difficult to say without seeing your code, but I suspect that you have created a new instance of your ListBox rather than clearing the existing one.

If this is not the case, then we would need to see a relevant code fragment.


"Yes, I posted my code above. Thank you"

That makes it clearer!
The answer is in your code:

private void ShowFolder(string a)
{
    listBox1.Items.Clear();
    //I can''t show data to listbox if I use this
    listBox2.Items.Clear();
    //I can''t show data to listbox if I use this
    string idenString = "folder";
    a = a.TrimStart(idenString.ToCharArray());
    string[] tempalate = a.Split(''^'');
    string folder = tempalate[0];
    string file = tempalate[1];
    string[] fld_entry = folder.Split(''\\'');
    string[] file_entry = file.Split(''\\'');
    controlSet = new capnhatCT(UpdateLB);
    for (int i = 0; i < fld_entry.Length; i++)
    {
        if (this.listBox1.InvokeRequired)
        {
            this.Invoke(controlSet,new object[] {fld_entry[i]});
        }
    }
    controlSet = new capnhatCT(UpdateLBFile);
    for (int i = 0; i < file_entry.Length; i++)
    {
        if (this.listBox2.InvokeRequired)
        {
            this.Invoke(controlSet, new object[] { file_entry[i] });
        }
    }
}



如果需要调用以将其添加到列表框,还需要调用以将其清除...



If you need an Invoke to add things to the ListBox, you will also need an Invoke to clear them out...


这篇关于在Pocket PC的编程应用程序上使用ListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆