一个GRIDVIEW的查询。
单几查询按纽查询。
以下是查询代码,(textBox1,2是条件)
 motormanTableAdapter.FillBy(vehicleManageDS.motorman , textBox1.Text.Trim(), textBox2.Text.Trim());
this.dataGridView1.ClearSelection();以下是CurrentCellChanged事件代码
        private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
        {
            try
            {if(dataGridView1 .CurrentRow .Index >=0 &&dataGridView1 .CurrentRow .Index <dataGridView1 .RowCount )
                {
                    currentindex = int.Parse(dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString());
                    vehicleManageDS.motormanRow mr = vehicleManageDS.motorman.NewmotormanRow();
                    CarM.vehicleManageDSTableAdapters.motormanTableAdapter ada = new CarM.vehicleManageDSTableAdapters.motormanTableAdapter();
                    mr = ada.GetDataByID(currentindex)[0];
                    if (!mr.IsPhoto1Null())
                    {
                        photobyte = (byte[])mr.Photo1;
                        System.IO.MemoryStream ms = new System.IO.MemoryStream(photobyte);
                        System.Drawing.Bitmap bmp = new Bitmap(ms);
                        pictureBox1.Image = bmp;
                    }
                    else
                    {
                        pictureBox1.Image = null;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }打开程序,填条件或不填条件搜索,没出错提示。然后第2次按查询,不管有没有条件,错误就来了。
拿掉CRY CATCH,
指出是
{if(dataGridView1 .CurrentRow .Index >=0 &&dataGridView1 .CurrentRow .Index <dataGridView1 .RowCount )
这一句。上面这句也拿掉,指出是这一句
currentindex = int.Parse(dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString());
这一句不能再拿了。