请问在(winfrom)里,怎么把checkBox添加到dataGrid行里! 请教大家在(winfrom)里,怎么把checkBox添加到dataGrid行里!多谢!!1 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 2005 DataGridView 带这个东西,直接用就可以等等吧 /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { connectionString="Provider=sqloledb;Data Source=zdq;Initial Catalog=MesDb;User Id=sa;Password=zdq;"; Connection = new OleDbConnection( connectionString ); Connection.Open(); OleDbDataAdapter da= new OleDbDataAdapter("SP_GET_PPMES202",Connection); DataSet ds = new DataSet(); da.Fill(ds,"table"); DataTable dt = new DataTable(); dt = ds.Tables["table"]; DataColumn dtcCheck = new DataColumn("aaa"); dtcCheck.DataType = System.Type.GetType("System.Boolean"); dtcCheck.DefaultValue = false; dt.Columns.Add(dtcCheck); dataGrid1.DataSource = dt; } private void button2_Click(object sender, System.EventArgs e) { DataTable ds_Table=(DataTable)this.dataGrid1.DataSource; DataRow [] dr=null; for(int i=0;i<ds_Table.Rows.Count;i++) { dr=ds_Table.Select("aaa=1"); } for(int i=0;i<dr.Length;i++) { MessageBox.Show(dr[i]["AUFNR"].ToString()); MessageBox.Show(dr[i]["SUB_AUFNR"].ToString()); MessageBox.Show(dr[i]["MATNR"].ToString()); MessageBox.Show(dr[i]["MAKT_Z"].ToString()); } } }} 参考一下:http://dev.csdn.net/develop/article/18/18615.shtmhttp://dev.csdn.net/develop/article/21/21585.shtmhttp://dev.csdn.net/develop/article/21/21294.shtm 楼上给的,都是asp的,有没有winform的我也正想学习,关注一下 兄弟们有WINForm的资料吗?? //winform也一样啊。DataTable dt = new DataTable();dt = ds.Tables["table"];DataColumn dtcCheck = new DataColumn("aaa"); dtcCheck.DataType = System.Type.GetType("System.Boolean"); dtcCheck.DefaultValue = false; dt.Columns.Add(dtcCheck); //这就加进去了。dataGrid1.DataSource=dt;dataGrid1.DataSource = dt; http://www.bypro.net/20069/ShowPost.aspx到上面的地址下载我写的软件,里面有你想要的东西。 按照楼上zdq801104的代码是可以添加CheckBox进去,但是这个CheckBox有3种选择,有什么办法改变选择的可能性,改为两种。 http://www.syncfusion.com/FAQ/WindowsForms/Default.aspx#44 http://shixianyong.cnblogs.com/archive/2005/06/15/174865.html fifadeke(咖啡淡了) 你好!请把代码发到谢谢! 好帖,正在思考该用listview还是datagrid的问题,谢了先...... 怎么都是给的asp.net的例子啊,我也碰到这个问题。 WinForm中DataGrid需要添加CheckBox嗎?給DataGrid添加一個DataGridTableStyle然后添加一個System.Windows.Forms.DataGridBoolColumn不就是你想要的CheckBox嗎? 試試看﹐不用寫代碼就能搞定的. 同意 sqfeiyu(流星雨) Dim myTableStyle As New DataGridTableStyle Dim tmpColumnCheck As New DataGridBoolColumn ...... tmpColumnCheck.MappingName = "EftposLink" tmpColumnCheck.AllowNull = False tmpColumnCheck.Width = 120 tmpColumnCheck.HeaderText = "EFTPOS Link" myTableStyle.GridColumnStyles.Add(tmpColumnCheck) ...... dtgPaymentTypes.TableStyles.Add(myTableStyle) 先通过设机器给Datagrid添加一个BOOL列DataGridBoolColumn,绑定的时候如果表里面有对应列则会直接显示,没有的话手动向表里面添加这样一列ds.Tables[0].Columns.Add(new DataColumn("check",typeof(Boolean))); dgCustomer.DataSource = ds.Tables[0]; DataTable dt=DBHelper.ExecuteDataTable("select * from h_info"); dt.Columns.Add(new DataColumn("check",typeof(Boolean))); this.dataGrid1.SetDataBinding(dt,""); http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx 很容易,在DataStyle中加个System.Windows.Forms.DataGridBoolColumn就行了。 Validate、Validating、新手求帮助 .net using()相关 根据身份证号判断是否成年(18周岁)? dataGridView的问题 DataColumn.AutoIncrement 如何重置? 这个绝对是个小小问题哦 我用VS2003 c# 最大化窗体,怎么连WINDOWS的任务栏也遮盖了 关于数据库连接关闭问题 statusStrip上如何用tooltip 如何php代码转化为C#代码? C#.net 对oralce9i的接口 急!!! com组件的问题
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
connectionString="Provider=sqloledb;Data Source=zdq;Initial Catalog=MesDb;User Id=sa;Password=zdq;";
Connection = new OleDbConnection( connectionString );
Connection.Open();
OleDbDataAdapter da= new OleDbDataAdapter("SP_GET_PPMES202",Connection);
DataSet ds = new DataSet();
da.Fill(ds,"table");
DataTable dt = new DataTable();
dt = ds.Tables["table"]; DataColumn dtcCheck = new DataColumn("aaa");
dtcCheck.DataType = System.Type.GetType("System.Boolean");
dtcCheck.DefaultValue = false; dt.Columns.Add(dtcCheck); dataGrid1.DataSource = dt; } private void button2_Click(object sender, System.EventArgs e)
{
DataTable ds_Table=(DataTable)this.dataGrid1.DataSource;
DataRow [] dr=null;
for(int i=0;i<ds_Table.Rows.Count;i++)
{
dr=ds_Table.Select("aaa=1");
}
for(int i=0;i<dr.Length;i++)
{
MessageBox.Show(dr[i]["AUFNR"].ToString());
MessageBox.Show(dr[i]["SUB_AUFNR"].ToString());
MessageBox.Show(dr[i]["MATNR"].ToString());
MessageBox.Show(dr[i]["MAKT_Z"].ToString());
} }
}
}
http://dev.csdn.net/develop/article/18/18615.shtm
http://dev.csdn.net/develop/article/21/21585.shtm
http://dev.csdn.net/develop/article/21/21294.shtm
我也正想学习,关注一下
有WINForm的资料吗??
DataTable dt = new DataTable();
dt = ds.Tables["table"];DataColumn dtcCheck = new DataColumn("aaa");
dtcCheck.DataType = System.Type.GetType("System.Boolean");
dtcCheck.DefaultValue = false; dt.Columns.Add(dtcCheck); //这就加进去了。
dataGrid1.DataSource=dt;dataGrid1.DataSource = dt;
你好!请把代码发到
谢谢!
給DataGrid添加一個DataGridTableStyle然后添加一個System.Windows.Forms.DataGridBoolColumn不就是你想要的CheckBox嗎? 試試看﹐不用寫代碼就能搞定的.
Dim tmpColumnCheck As New DataGridBoolColumn
......
tmpColumnCheck.MappingName = "EftposLink"
tmpColumnCheck.AllowNull = False
tmpColumnCheck.Width = 120
tmpColumnCheck.HeaderText = "EFTPOS Link"
myTableStyle.GridColumnStyles.Add(tmpColumnCheck) ...... dtgPaymentTypes.TableStyles.Add(myTableStyle)
绑定的时候如果表里面有对应列则会直接显示,没有的话手动向表里面添加这样一列
ds.Tables[0].Columns.Add(new DataColumn("check",typeof(Boolean)));
dgCustomer.DataSource = ds.Tables[0];
dt.Columns.Add(new DataColumn("check",typeof(Boolean)));
this.dataGrid1.SetDataBinding(dt,"");