解决方案 »

  1.   

    思路有了,但不知道怎么写语句? 
    浏览用 openDialogFile
    打开文件 System.IO.File
      

  2.   

    对的,这个是在button里实现呀,但是我需要在combobox的事件里敲代码把,但是不知道应该怎么敲··
      

  3.   

    对的,这个是在button里实现呀,但是我需要在combobox的事件里敲代码把,但是不知道应该怎么敲··

    双击combobox,然后在那里敲代码。
      

  4.   

    点浏览的时候combobox.selected值拿出来  然后去查询就可以了啊
      

  5.   

    这个不难阿,选择菜单项,对应打开文本,将文件内容显示在datagridview中,是这样?
      

  6.   

    简单一个例子
     private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if ((sender as ComboBox).Text.Equals("111"))
                {
                    MessageBox.Show("111");//你可以在这里放你的操作  对应的都是ComboBox的选项值
                }
            }
      

  7.   

    我简单给你写一个,
    用comboBox1,存要素如你的抬扛法地形,我这里用1,2,3,4,
     textBox1显示所对应的文本文件路径,其中的数据之间以一个空格
    一个“浏览”命令钮,然后一个datagridview控件   private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (comboBox1.SelectedItem.ToString() == "1")
                {
                    textBox1.Text = Application.StartupPath + "\\txt\\1.txt";
                }
                else if (comboBox1.SelectedItem.ToString() == "2")
                {
                    textBox1.Text = Application.StartupPath + "\\txt\\2.txt";
                }
                else if (comboBox1.SelectedItem.ToString() == "3")
                {
                    textBox1.Text = Application.StartupPath + "\\txt\\3.txt";
                }
                else if (comboBox1.SelectedItem.ToString() == "4")
                {
                    textBox1.Text = Application.StartupPath + "\\txt\\4.txt";
                }
            }        private void button1_Click(object sender, EventArgs e)
            {          
               
                    //新建一个datatable用于保存读入的数据
                    DataTable dt = new DataTable();
                    //给datatable添加三个列
                    dt.Columns.Add("aa", typeof(String));
                    dt.Columns.Add("bb", typeof(String));
                    dt.Columns.Add("cc", typeof(String));
                    dt.Columns.Add("dd", typeof(String));
                    //读入文件
                    using (StreamReader reader = new StreamReader(textBox1.Text, Encoding.Default))
                    {
                        //循环读取所有行
                        while (!reader.EndOfStream)
                        {
                            //将每行数据,用-分割成3段
                            string[] data = reader.ReadLine().Split(' ');//每行数据之间有一个空格 
                            //新建一行,并将读出的数据分段,分别存入对应的列中,有几列建立几个
                            DataRow dr = dt.NewRow();
                            dr[0] = data[0];
                            dr[1] = data[1];
                            dr[2] = data[2];
                            dr[3] = data[3];
                            //将这行数据加入到datatable中
                            dt.Rows.Add(dr);
                        }
                    }
                    //将datatable绑定到datagridview上显示结果
                    this.dataGridView1.DataSource = dt;
               
            }
      

  8.   

    我觉得你直接把数据 存到Datatable中,然后绑定数据源,这样你选择的时候就可以把你要的数据直接显示出来