最近小菜鸟我在学c#,很久以前用的是那个VFP,想把一个以前写的vfp程序,改为c#的,也算是边学学做啦在用到dataGridView的时候,有个问题总是弄不好,
比如有个tyjs.mdb,里面的字段有ftyjsh,fxb,pb等
我在winform 中插入了dataGridView,在调试中,dataGridView也正常表中的数据可是,我在cellclick 事件中
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            this.textBox1.Text = this.dataGridView1["FTYJSH", this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
            this.textBox2.Text = this.dataGridView1["FXB", this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
         
        }在调试中,不管我选中哪一行,textbox1,和2怎么都是空的,请问这是怎么一回事以下是全部的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“tyjsDataSet.tyjs”中。您可以根据需要移动或删除它。
            this.tyjsTableAdapter.Fill(this.tyjsDataSet.tyjs);        }
        private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
        {        }        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            this.textBox1.Text = this.dataGridView1["FTYJSH", this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
            this.textBox2.Text = this.dataGridView1["FXB", this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
            
        }    }
}

解决方案 »

  1.   

    在CellClick事件里加断点调试,看看结果
      

  2.   

    我现在将那个
       private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
            {
                this.textBox1.Text = "ddddd";
                this.textBox2.Text = this.dataGridView1["FXB", this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
                this.label1.Text = this.dataGridView1["FXB",this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
            }改为这样,居然还是没有反映,是不是这个事件需要什么激活?还是怎么之
      

  3.   

    真是怪事,我非要把  dataGridView1,里的事件cellclick 搞个别名,
     private void ddd(object sender, DataGridViewCellEventArgs e)
            {
                textBox1.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            }这样才行,这是为什么?