如何在列表框中显示xml搜索数据 [英] how to display xml searching data in to listbox

查看:102
本文介绍了如何在列表框中显示xml搜索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
我对此很陌生.
我正在搜索我在文本框中输入的xml文件中的数据(确定).我会将比赛数据输入到messagbox中,但无法显示在列表框中.
任何人都知道的方式.
我的要求是
我想在列表框中显示,然后单击列表框中的任何值,该值将转到文本框.
请给我任何想法.
听到是我的代码

Hi friends ,
i m new for this.
i am searching the data in xml file what i entered in textbox (this ok). i ll take matches data in to messagbox but i m not able to display in listbox .
way any one knows.
my requirement is
i want to display in listbox and then i click any value in listbox that value gos to textbox.
please give me any idea.
hear is my code

private void textBox2_TextChanged(object sender, EventArgs e)
        {
            string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            XDocument doc = XDocument.Load(path + @"\Refrigirater.xml"); // or whatever thew file''s called
            string search = textBox2.Text.Trim();
            //to search particular column in xml database
            string[] results = (from element in doc.Element("DATAPACKET").Elements("data1").Elements("R_PRE") where element.Value.StartsWith(search) select element.Value).ToArray();
            //to search in all columns table
            //string[] results = (from element in doc.Element("DATAPACKET").Elements("data1").Elements() where element.Value.StartsWith(search) select element.Value).ToArray();
            if (textBox2.Text == "")
            {
                MessageBox.Show("Please Enter Value");
            }
            else
            {
                if (results.Length > 0)
                {
                    string message = String.Join("\r\n", results);
                    MessageBox.Show("\r\n" + message);
                }
                else
                {
                    MessageBox.Show("No matches were found");
                }
            }


我正在搜索的内容都与消息ll中的数据匹配.
请给我任何想法.
谢谢
Venkat.S


what i m searching that all matches data in message ll there.
please give me any idea.
Thanks
Venkat.S

推荐答案

首先尝试创建一个新窗体(ChildForm),在其中添加一个ListBox,
并创建一个公共函数来设置数据源.



然后在要搜索的表单中,尝试搜索XML并获取一个集合.
创建一个新的ChildForm实例,然后调用该方法来设置数据源.
并将表单显示为对话框.
尝试使用委托在selectionindex更改事件上传递数据.

谢谢,
Debata
First try to Create a new Form (ChildForm), Where you add a ListBox,
And create a public function to set the datasouce.



Then in the form where you are searching, Try to search the XML and get a collection.
Create a new instance of ChildForm and call the method to set the data source.
and show the form as a dialog.
Try to use delegate to pass data on selectionindex change event.

Thanks,
Debata


这篇关于如何在列表框中显示xml搜索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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