本文介绍了如何在不使用数据库的情况下从数据网格中全局搜索数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我从串口接收数据并直接在datagrid上显示。现在我想在网格中包含数据的搜索选项。这是我将数据放入网格的代码。



Hi all. I'm receiving data from the serial port and displaying it directly on the datagrid. Now i want to include search option for the data's in the grid. Here is the code how i put data into the grid.

SerialPort sp1 = (SerialPort)sender;
            SerialPort sp3 = (SerialPort)sender;
           // Thread.Sleep(200);
            string data = sp1.ReadExisting();
            string data2 = sp3.ReadExisting();

            this.BeginInvoke(new MethodInvoker(delegate()
            {
                if (data.ToString() != null)
                {
                    richTextBox1.SelectionColor =colorDialog1.Color;
                    richTextBox1.SelectedText = Environment.NewLine +data.ToString();
                    //richTextBox1.AppendText("\n\n" + comboBox1.Text + "::");
                    //this.richTextBox1.Text = richTextBox1.Text + data.ToString();

                }
                if (data2.ToString() != null)
                {
                    richTextBox1.SelectionColor = Color.Black; ;
                    richTextBox1.SelectedText = Environment.NewLine + data2.ToString();
                    //richTextBox1.AppendText("\n\n 2nd PORT::");
                    //this.richTextBox1.Text = richTextBox1.Text + data2.ToString();
                }
                 this.richTextBox2.Text += data.ToString();

                 string x = richTextBox2.Text;

                //richtext box autoscrolling
                richTextBox1.SelectionStart = richTextBox1.Text.Length;
                richTextBox1.ScrollToCaret();
                dataGridView1.FirstDisplayedCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0];



                //splitting and gettig character count

                if (x.Contains("**") && x.Contains("$"))
                {
                    //string match = x.Split(new string[] { "**" }, StringSplitOptions.None)[1].Split('$')[0].Trim();
                    //int le = match.Length;


                    // filter data using start and end character and split operation
                    var temp = x.Split(new string[] { "**" }, StringSplitOptions.RemoveEmptyEntries);
                    List<string> result = new List<string>();
                    foreach (string item in temp)
                        result.AddRange(item.Split(new string[] { "$" }, StringSplitOptions.RemoveEmptyEntries));


                    foreach (String s in result)
                    {
                        richTextBox2.Text = s.ToString() + "\r\n";

                    }

                    string fn = richTextBox2.Text;

                    //if (fn.Length > le)
                    //{
                        string[] d = fn.Split('-');

                        dataGridView1.Rows.Add(d);



请帮我从datagridview搜索数据。



我尝试了什么:



我试图搜索这样的数据。



DataView dv = new DataView();

dv.RowFilter = string.Format([+ comboBox2.Text +] LIKE'%{0 }%',textBox2.Text);

dataGridView1.DataSource = dv;



我想从数据网格全局搜索数据使用列名。在此先感谢。


Please help me to search data from the datagridview.

What I have tried:

I have tried to search data like this.

DataView dv = new DataView();
dv.RowFilter = string.Format("[" + comboBox2.Text + "] LIKE '%{0}%'", textBox2.Text);
dataGridView1.DataSource = dv;

I want to search data's globally from the datagrid without using column names. Thanks in advance.

推荐答案





请帮我从datagridview搜索数据。



我尝试了什么:



我试图搜索这样的数据。



DataView dv = new DataView();

dv.RowFilter = string.Format([+ comboBox2.Text +] LIKE'%{0 }%',textBox2.Text);

dataGridView1.DataSource = dv;



我想从数据网格全局搜索数据使用列名。提前致谢。


Please help me to search data from the datagridview.

What I have tried:

I have tried to search data like this.

DataView dv = new DataView();
dv.RowFilter = string.Format("[" + comboBox2.Text + "] LIKE '%{0}%'", textBox2.Text);
dataGridView1.DataSource = dv;

I want to search data's globally from the datagrid without using column names. Thanks in advance.


这篇关于如何在不使用数据库的情况下从数据网格中全局搜索数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 20:19