急!!我是新手,望各位大哥回答!

lovepei99 2004-12-21 07:21:52
在一个WINDOWS应用程序中
放置 一个COMBOBOX控件,和一个DATAGRID
希望在FORM_LOAD事件中先绑定COMBOBOX,
然后在COMBOBOX中有一个SelectedIndexChanged 事件
希望在COMBOBOX里选择一个直之后能在DATAGRID中显示出符合所选值的几列数据

哪位大哥告诉我啊~~~~~不胜感激!!
...全文
105 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovepei99 2004-12-21
  • 打赏
  • 举报
回复
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OracleClient;

namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox4;


private string ConString="Data Source=oradb1;User Id=htl_manager;Password=111;";
private DataSet ruzhuDs;
private OracleConnection ruzhuConn ;
private OracleDataAdapter ruzhuDa;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

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

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(144, 248);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(392, 80);
this.dataGrid1.TabIndex = 0;
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(144, 80);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 1;
this.comboBox1.Text = "comboBox1";
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(144, 128);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(112, 21);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(384, 144);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 3;
this.textBox2.Text = "textBox2";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(144, 192);
this.textBox3.Name = "textBox3";
this.textBox3.TabIndex = 4;
this.textBox3.Text = "textBox3";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(408, 176);
this.textBox4.Name = "textBox4";
this.textBox4.TabIndex = 5;
this.textBox4.Text = "textBox4";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(616, 445);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{

//BindCombobox();
ruzhuConn= new OracleConnection(ConString);

string strSql="select * from room_lev_table ";
ruzhuDs= new DataSet("room_lev_table");
//DataSet ds=new DataSet("room_table");
//OracleDataAdapter da=new OracleDataAdapter(strSql,cn);
ruzhuDa = new OracleDataAdapter(strSql,ruzhuConn);
ruzhuDa.Fill(ruzhuDs,"room_lev_table");

comboBox1.DataSource=ruzhuDs.Tables["room_lev_table"];
comboBox1.DisplayMember = ruzhuDs.Tables ["room_lev_table"].Columns[1].ColumnName;
comboBox1.ValueMember = ruzhuDs.Tables["room_lev_table"].Columns[0].ColumnName;
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
ruzhuConn= new OracleConnection(ConString);
string strSql="select * from room_table where room_num='"+comboBox1.SelectedValue+"'";
ruzhuDs=new DataSet("room_table");
ruzhuDa=new OracleDataAdapter(strSql,ruzhuConn);
ruzhuDa.Fill(ruzhuDs);
dataGrid1.DataSource = ruzhuDs;
dataGrid1.DataMember ="room_table";
}

各位大哥帮忙看看啊!


Alden 2004-12-21
  • 打赏
  • 举报
回复
应该很简单的,你好好检查检查代码,或者把代码贴出来。
hanyaocsdn 2004-12-21
  • 打赏
  • 举报
回复
up
Ivony 2004-12-21
  • 打赏
  • 举报
回复
据你所说,最有可能就是你的cs文件里面的控件的名字(如DataGrid)与你的aspx文件里面的标签(如<asp:DataGrid.....>)的ID属性不匹配。
lovepei99 2004-12-21
  • 打赏
  • 举报
回复
我每次运行都会出现 “未将对象引用设置到对象的实例”?

这是什么意思啊
怎么解决~
急!
lovepei99 2004-12-21
  • 打赏
  • 举报
回复
InterMa(因特马) 大哥 ,帮帮忙啊 !
InterMa 2004-12-21
  • 打赏
  • 举报
回复
这个。。。。。。。。
你都说的相当明白了,没什么难点阿,怎么不会编呢?

111,098

社区成员

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

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

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