如何把数据写入DataGrid中去?

superman7826 2003-08-20 06:23:07
如何把数据写到DataGrid中,给点代码吧!
同时,在C#下面,如何判断字符串是数值形的呢?谢谢!
...全文
26 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
kuangren 2003-08-21
  • 打赏
  • 举报
回复
用Table.Rows.Add()就可以了~
wf5360308(峰) 那里已经说了很清楚了!
烤火的鱼 2003-08-21
  • 打赏
  • 举报
回复
直接修改dataset。
冷月孤峰 2003-08-21
  • 打赏
  • 举报
回复
很简单的,看一下代码就会了
DataRow a=dataSet31.Tables["表名"].NewRow();
a[0]=textBox1.Text;
a[1]=textBox2.Text;
a[2]=comboBox1.Text;
a[3]=textBox3.Text;
a[4]=dateTimePicker1.Text;
a[5]=dateTimePicker2.Text;
a[7]=comboBox2.Text;
a[6]=dateTimePicker3.Text;
a[8]=textBox4.Text;
a[9]=textBox5.Text;
a[10]=textBox6.Text;

dataSet31.Tables["表名"].Rows.Add(a);

sqlDataAdapter1.Update(dataSet31,"表名");
alphawin 2003-08-21
  • 打赏
  • 举报
回复
DataGrid.Rows.Add就可以了
Amilsx 2003-08-20
  • 打赏
  • 举报
回复
To : net_lover(孟子E章) ( ) 信誉:115

你的网站的美工真该找个专业点的人来给你改改.挺难看的.................

呵呵
雪狼1234567 2003-08-20
  • 打赏
  • 举报
回复
或者从这儿下一个例子程序
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q773q

5.16 How can I do cell by cell validation in a datagrid?

There are problems trying to implement cell by cell validation using the grid's Validating event architecture. The problem is that the grid is not the object handling the data. Instead, a TextBox or some other control is the control managing the changing of the cell contents. One way to implement the validation at the grid level is to handle the CurrentCellChanged event, and if the previous cell's value is not proper, then return to that cell. You can download a sample that implements this process. The sample only handles the validation from cell to cell movement. If you want to handle the validation when the user clicks on the forms Close button, then you would have to add a special event handler for this and do one last validation at this point.

雪狼1234567 2003-08-20
  • 打赏
  • 举报
回复
5.12 How can I restrict the keystrokes that will be accepted in a column of my datagrid?

You can create a custom column style and handle the KeyPress event of its TextBox member. Below is the code showing how this might be done. You can also download a sample project (C#, VB) that shows an implementation of this idea.

public class DataGridDigitsTextBoxColumn : DataGridTextBoxColumn

{

public DataGridDigitsTextBoxColumn(System.ComponentModel.PropertyDescriptor pd, string format, bool b)

: base(pd, format, b)

{

this.TextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(HandleKeyPress);

}



private void HandleKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)

{

//ignore if not digit or control key

if(!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar))

e.Handled = true;



//ignore if more than 3 digits

if(this.TextBox.Text.Length >= 3 && !char.IsControl(e.KeyChar))

e.Handled = true;

}



protected override void Dispose(bool disposing)

{

if(disposing)

this.TextBox.KeyPress -= new System.Windows.Forms.KeyPressEventHandler(HandleKeyPress);



base.Dispose(disposing);

}

}

hq1305018 2003-08-20
  • 打赏
  • 举报
回复
1、你首先建立一个DataRow对象,把数据添加到该对象中。DataGrid.Rows.Add方法可以增加新行。
2、
String aa="12345a";
try
{
Console.WriteLine(Convert.ToInt32(aa));
}
catch(Exception ex)
{
Console.Write("格式不正确");
}
孟子E章 2003-08-20
  • 打赏
  • 举报
回复
http://xml.sz.luohuedu.net/xml/Content.asp

110,533

社区成员

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

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

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