最近小菜鸟我在学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();
} }
}
比如有个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();
} }
}
解决方案 »
- 求高手指教,如何用C#将本地txt文件中的内容添加到excel表格中?
- 关于在窗口中把焦点固定在其中一个控件上该怎么写
- 海量数据搜索问题
- 加密锁问题
- C# .net2005与2003 是如何使用SoapHeader与WebService通信的。
- winform中如何将文件上传到服务器指定的路径
- 求一xpath表达式:
- 请问请问请问DataGrid DataSet xml结合的问题!!!
- --------------------treeview的问题.在进行了数据邦定之后.显示的数据没有级连接.--------------------------
- C# winform为什么界面总死掉?
- 求教C#调用c++ dll函数声明的问题
- C#鼠标单击事件代码问题
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();
}改为这样,居然还是没有反映,是不是这个事件需要什么激活?还是怎么之
private void ddd(object sender, DataGridViewCellEventArgs e)
{
textBox1.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
}这样才行,这是为什么?