绑定的问题

ju_feng 2003-02-25 10:53:00

public class Form1 : System.Windows.Forms.Form
{
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Data.DataSet ds = new System.Data.DataSet();
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
InitialDataAdapte();
}

private void InitialDataAdapte()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();

this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "BASE_MATERIAL", new System.Data.Common.DataColumnMapping[]
this.sqlSelectCommand1.CommandText = "SELECT WLDM, WLXH, WLMC FROM BASE_MATERIAL";
this.sqlSelectCommand1.Connection = this.sqlConnection1;

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
this.sqlDataAdapter1.Fill(ds);
this.comboBox1.DataSource=ds;
this.comboBox1.DisplayMember ="BASE_MATERIAL.WLMC";
this.comboBox1.ValueMember="BASE_MATERIAL.WLDM";
this.BindingContext[this.comboBox1.DataSource,"BASE_MATERIAL"].SuspendBinding();
this.BindingContext[this.comboBox1.DataSource,"BASE_MATERIAL"].ResumeBinding();
}

private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
MessageBox.Show(this.ds.Tables[0].Rows[this.BindingContext[this.comboBox1.DataSource,"BASE_MATERIAL.WLMC"].Position]["WLDM"].ToString().Trim());
}
我用设计器生成的数据集绑定,同样代码可以得到相应的Position,但自己代码生成一个dataset再填充绑定,就不能取到相应的position值
...全文
66 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
cqnimin 2003-02-27
  • 打赏
  • 举报
回复
hehe 解决了三

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧