数据网格视图光标
我的数据网格显示来自我的 sqlBd 的表。我为每列添加一个文本框来显示每行。
这是我的代码:
private void CustomerViewToolStripMenuItem_Click(object sender, EventArgs e)
{
BindingSource Clients_bs = new BindingSource();
SqlConnection con = new SqlConnection(dc.Con);
con.Open();
da.SelectCommand = new SqlCommand("SELECT * FROM Clients", con);
da.Fill(dt);
con.Close();
dgCustomers.DataSource = dt;
Clients_bs.DataSource = dt;
txtBoxIdCustomers.DataBindings.Add(new Binding("Text", Clients_bs,"id_Client"));
txtBoxFullName.DataBindings.Add(new Binding("Text", Clients_bs, "prénom_Nom"));
txtBoxAddress.DataBindings.Add(new Binding("Text", Clients_bs, "adresse"));
txtBoxCity.DataBindings.Add(new Binding("Text", Clients_bs, "ville"));
txtBoxProvince.DataBindings.Add(new Binding("Text", Clients_bs, "province"));
txtBoxPostal.DataBindings.Add(new Binding("Text", Clients_bs, "code_Postal"));
txtBoxPhone.DataBindings.Add(new Binding("Text", Clients_bs, "numéro_Teléphone"));
}
它像 SQL 中的表一样填充我的 dataGrid,并且我的 txtbox 仅显示光标指向 dataGrid 中第一行的第一行。
我想移动第二行数据网格的光标,并在第二行自动显示txtbox的绑定....
我可以让一个按钮上一个和下一个,但不能让光标...
谢谢你帮助我!
My datagrid show a table from my sqlBd. I add a textBox for each column that for show each rows.
This is my code:
private void CustomerViewToolStripMenuItem_Click(object sender, EventArgs e)
{
BindingSource Clients_bs = new BindingSource();
SqlConnection con = new SqlConnection(dc.Con);
con.Open();
da.SelectCommand = new SqlCommand("SELECT * FROM Clients", con);
da.Fill(dt);
con.Close();
dgCustomers.DataSource = dt;
Clients_bs.DataSource = dt;
txtBoxIdCustomers.DataBindings.Add(new Binding("Text", Clients_bs,"id_Client"));
txtBoxFullName.DataBindings.Add(new Binding("Text", Clients_bs, "prénom_Nom"));
txtBoxAddress.DataBindings.Add(new Binding("Text", Clients_bs, "adresse"));
txtBoxCity.DataBindings.Add(new Binding("Text", Clients_bs, "ville"));
txtBoxProvince.DataBindings.Add(new Binding("Text", Clients_bs, "province"));
txtBoxPostal.DataBindings.Add(new Binding("Text", Clients_bs, "code_Postal"));
txtBoxPhone.DataBindings.Add(new Binding("Text", Clients_bs, "numéro_Teléphone"));
}
That fill my dataGrid like my table in sql, and my txtbox's shows the first row only whit the cursor pointing on the first row in my dataGrid.
I want to move the cursor of the data grid on the second row and show txtbox's bind automatically on the second row ....
I can make whit a button previous and next, but not whit the cursor...
Thank's for helping me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是这样:这样
做:
那么它应该可以工作,因为文本框和网格具有相同的 BindingSource ;-)
编辑:
另外,请不要这样做:
这样做:
instead of this:
do this:
then it should work as the TextBoxes and the Grid have the same BindingSource ;-)
Edit:
and also, please, instead of this:
do this: