从Delphi转入.Net,遇到了第一个问题,望大家热情帮助 知道了,利用数据邦定就可以了。BindingManagerBase 这个实例。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考如下代码,不全但够用了private BindingManagerBase bind;OleDbConnection conn=new OleDbConnection(strConn);conn.Open();DataSet ds=new DataSet();OleDbDataAdapter da=new OleDbDataAdapter(strSQL,conn);da.Fill(ds,"Test");conn.Close();bind=this.BindingContext[ds,"Test"];bind.Position=0;textBoxID.DataBindings.Add("Text",ds,"Test.ID");textBoxName.DataBindings.Add("Text",ds,"Test.Name");private void PrevRecord()//显示上一条记录 { if(bind.Position==0) { MessageBox.Show("已经到了第一条记录!","警告!",MessageBoxButtons.OK,MessageBoxIcon.Warning); } if(bind.Position==-1) { MessageBox.Show("已经没有记录可浏览!","警告!",MessageBoxButtons.OK,MessageBoxIcon.Warning); } else { bind.Position-=1; } } 用绑定可以,用别的办法也可以做到;看我的 private void dataGridView1_CursorChanged(object sender, EventArgs e) { int a=dataGridView1.CurrentCell.RowIndex; textBox2.Text = dataGridView1.Rows[a].Cells[0].Value.ToString(); textBox3.Text = dataGridView1.Rows[a].Cells[1].Value.ToString(); textBox4.Text = dataGridView1.Rows[a].Cells[2].Value.ToString(); textBox5.Text = dataGridView1.Rows[a].Cells[3].Value.ToString(); textBox6.Text = dataGridView1.Rows[a].Cells[4].Value.ToString(); } 一般就是用数据邦定了,,。net中的text等控件都有一个datasource 属性的,,就相当与delphi 中的“数据显示控件”(我也是从delphi 转过来的不过名字不清楚了,好久没用了,呵呵)那一栏的text控件 SelectedIndexChanged这个事件对你应该有用 数据绑定吧,如果想把简单的工作弄的更复杂一点可以参考如下代码 DataView dv=new DataView(); int i=0; foreach(DataRowView dr in dv) { ((TextBox)this.FindControl(editID+i)).Text=dr["ID"]; ((TextBox)this.FindControl(editName+i)).Text=dr["Name"]; } i++; } 楼上也都提到了,用BindingManagerBase,具体解释MSDN里面多了慢慢查 请教 C#中如何设置随机种子 项目实时请教,还没入门。。。。。高手速来指点。。。。。 dataGridView数据绑定出现这个怎么解决 关于。net调用com,为什么不推荐直接用 class来定义 对象? 请问那有C#方面的简单试题? 请教DataGrid的问题 设置pdf和excel显示百分数格式 帮我 写一个简单C#画图程序啊 ! 如何编写程序监视局域网用户对共享文件夹的访问? 很大意见!!! 为什么删我帖子?支持的朋友替我说句公道话 50分求解!!!如何把。ASPX文件里的文本框变量提交到一个ASP的接收文件!!!!!(菜鸟级问题,进者有分) 初学者的一个问题,谢谢回答。
private BindingManagerBase bind;
OleDbConnection conn=new OleDbConnection(strConn);
conn.Open();
DataSet ds=new DataSet();
OleDbDataAdapter da=new OleDbDataAdapter(strSQL,conn);
da.Fill(ds,"Test");
conn.Close();
bind=this.BindingContext[ds,"Test"];
bind.Position=0;
textBoxID.DataBindings.Add("Text",ds,"Test.ID");
textBoxName.DataBindings.Add("Text",ds,"Test.Name");private void PrevRecord()//显示上一条记录
{
if(bind.Position==0)
{
MessageBox.Show("已经到了第一条记录!","警告!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
if(bind.Position==-1)
{
MessageBox.Show("已经没有记录可浏览!","警告!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
else
{
bind.Position-=1;
}
}
private void dataGridView1_CursorChanged(object sender, EventArgs e)
{
int a=dataGridView1.CurrentCell.RowIndex;
textBox2.Text = dataGridView1.Rows[a].Cells[0].Value.ToString();
textBox3.Text = dataGridView1.Rows[a].Cells[1].Value.ToString();
textBox4.Text = dataGridView1.Rows[a].Cells[2].Value.ToString();
textBox5.Text = dataGridView1.Rows[a].Cells[3].Value.ToString();
textBox6.Text = dataGridView1.Rows[a].Cells[4].Value.ToString();
}
。net中的text等控件都有一个datasource 属性的,,就相当与delphi 中的“数据显示控件”(我也是从delphi 转过来的不过名字不清楚了,好久没用了,呵呵)那一栏的text控件
这个事件对你应该有用
int i=0;
foreach(DataRowView dr in dv)
{
((TextBox)this.FindControl(editID+i)).Text=dr["ID"];
((TextBox)this.FindControl(editName+i)).Text=dr["Name"];
}
i++;
}