| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 611 人关注过本帖
标题:[求助]谁能帮我看看这个问题
只看楼主 加入收藏
hehe6021275
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-6-6
收藏
 问题点数:0 回复次数:7 
[求助]谁能帮我看看这个问题

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace WindowsApplication24
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/// <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.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
((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(8, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(488, 200);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
//
// button1
//
this.button1.Location = new System.Drawing.Point(8, 272);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "添加";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 224);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 23);
this.label1.TabIndex = 2;
this.label1.Text = "label1";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(80, 224);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(72, 21);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(248, 224);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(72, 21);
this.textBox2.TabIndex = 5;
this.textBox2.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(168, 224);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 23);
this.label2.TabIndex = 4;
this.label2.Text = "label2";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(408, 224);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(72, 21);
this.textBox3.TabIndex = 7;
this.textBox3.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(328, 224);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 23);
this.label3.TabIndex = 6;
this.label3.Text = "label3";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(408, 272);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(72, 21);
this.textBox4.TabIndex = 9;
this.textBox4.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(328, 272);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(80, 23);
this.label4.TabIndex = 8;
this.label4.Text = "label4";
//
// button2
//
this.button2.Location = new System.Drawing.Point(120, 272);
this.button2.Name = "button2";
this.button2.TabIndex = 10;
this.button2.Text = "button2";
//
// button3
//
this.button3.Location = new System.Drawing.Point(232, 272);
this.button3.Name = "button3";
this.button3.TabIndex = 11;
this.button3.Text = "button3";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(512, 318);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.label4);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.label3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
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>
///
private DataSet ds=new DataSet();
private SqlConnection conn;
private SqlDataAdapter da;
private SqlParameter par=new SqlParameter();
private DataTable table=new DataTable();
private CurrencyManager man;

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

private void button1_Click(object sender, System.EventArgs e)
{
try
{
DataRow row=this.ds.Tables["jobs"].NewRow();
row["job_id"]=this.textBox1.Text;
row["job_desc"]=this.textBox2.Text;
row["min_lvl"]=this.textBox3.Text;
row["max_lvl"]=this.textBox4.Text;
this.ds.Tables["jobs"].Rows.Add(row);
this.ds.HasChanges(DataRowState.Added);
this.da.Update(this.ds,"jobs");
MessageBox.Show("添加成功");
this.textBox1.Clear();
this.textBox2.Clear();
this.textBox3.Clear();
this.textBox4.Clear();
this.dataGrid1.Update();
this.textBox1.Focus();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}

private void Form1_Load(object sender, System.EventArgs e)
{
this.textBox1.Enabled=false;
conn=new SqlConnection("server=.;uid=sa;pwd=;database=pubs");
this.da=new SqlDataAdapter("select *from jobs",conn);
this.da.Fill(this.ds,"jobs");
this.dataGrid1.DataSource=this.ds;
this.dataGrid1.DataMember="jobs";
this.da.Fill(this.table);
this.dataGrid1.DataSource=this.table.DefaultView;
this.man=(CurrencyManager)BindingContext[this.table];
this.dataGrid1.SetDataBinding(this.ds,"jobs");
string incmd="insert into jobs values(@job_id,@job_desc,@min_lvl,@max_lvl)";
this.da.InsertCommand=new SqlCommand(incmd,conn);
this.par=this.da.InsertCommand.Parameters.Add("@job_id",SqlDbType.SmallInt,2);
this.par.SourceColumn="job_id";
this.par.SourceVersion=DataRowVersion.Current;
this.par=this.da.InsertCommand.Parameters.Add("@job_desc",SqlDbType.VarChar,50);
this.par.SourceColumn="job_desc";
this.par.SourceVersion=DataRowVersion.Current;
this.par=this.da.InsertCommand.Parameters.Add("@min_lvl",SqlDbType.TinyInt,1);
this.par.SourceColumn="min_lvl";
this.par.SourceVersion=DataRowVersion.Current;
this.par=this.da.InsertCommand.Parameters.Add("@max_lvl",SqlDbType.TinyInt,1);
this.par.SourceColumn="max_lvl";
this.par.SourceVersion=DataRowVersion.Current;
zq();
}
private void zq()
{
try
{
this.textBox1.DataBindings.Add("Text",this.table,"job_id");
this.textBox2.DataBindings.Add("Text",this.table,"job_desc");
this.textBox3.DataBindings.Add("Text",this.table,"min_lvl");
this.textBox4.DataBindings.Add("Text",this.table,"max_lvl");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}

private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
if(this.table.Rows.Count>0)
{
int count=this.dataGrid1.CurrentCell.RowNumber;
if(count>0&&count<=this.man.Count)
{
this.man.Position=count;
}
}
}

}
}
问题是我在点添加按鈕是怎么让下面的文本框数据自动清空~~!@@!@

搜索更多相关主题的帖子: private public 
2007-03-30 10:19
卡洛
Rank: 2
等 级:论坛游民
威 望:2
帖 子:185
专家分:40
注 册:2007-3-23
收藏
得分:0 
把文本框里附个空格不就行了?

2007-03-30 11:04
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
this.textBox1.Clear();

飘过~~
2007-03-30 12:26
hehe6021275
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-6-6
收藏
得分:0 
回复:(bygg)this.textBox1.Clear();
this.textBox1.Clear();
这个方法不行的
2007-03-30 12:47
天使不哭
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:677
专家分:22
注 册:2006-7-9
收藏
得分:0 
发这么长的代码让人怎么看你的关键代码啊,
清空textbox中的文本,
你只需要在按下按钮的时候写上this.textbox.clear()或者this.textbox.text="";
就行了啊
那个textbox是你的那个控件的名称.

C#Winform技术群:25380362
博客:http:///boyliupan/
2007-03-30 13:19
IT浪子
Rank: 4
来 自:Nyist
等 级:贵宾
威 望:13
帖 子:402
专家分:20
注 册:2006-11-24
收藏
得分:0 
楼上的方法应该可以帮你搞定的吧

你不能让所有人都满意,因为不是所有人都是人!
2007-03-30 17:49
hehe6021275
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-6-6
收藏
得分:0 
回复:(IT浪子)楼上的方法应该可以帮你搞定的吧
我知道用this.textBox.Clear()可以清空
但是我是把dataGrid1的数据绑定到textBox里
就是说我点dataGrid1的数据时候在下面的的textBox显示数据
问题是我要增加数据的时候怎么让dataGrid1的数据时候在下面的的textBox不显示数据
显示为空
但你们所说的方法不可以的再说我的代码上也有this.textBox.Clear()这个方法呀!
你们可以试试看撒...................
2007-04-02 18:42
hehe6021275
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-6-6
收藏
得分:0 
回复:(hehe6021275)回复:(IT浪子)楼上的方法应该...
有人吗?
帮帮我呀[em11" target="_blank" >!@!#!#!@!@!@!21[em11]
2007-04-02 19:20
快速回复:[求助]谁能帮我看看这个问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029769 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved