绑定的问题

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值
...全文
36 1 打赏 收藏 举报
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
cqnimin 2003-02-27
hehe 解决了三
  • 打赏
  • 举报
回复
发帖
C#
加入

10.7w+

社区成员

.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
申请成为版主
帖子事件
创建了帖子
2003-02-25 10:53
社区公告

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