如何在DataGrid中加入另一个控件,例如加入一个ComboBox?
如何在DataGrid中加入另一个控件,例如加入一个ComboBox? 问题点数:100、回复次数:16Top
1 楼reanna(蕾安娜)回复于 2002-03-05 17:15:55 得分 0
在windows form 下Top
2 楼dessert(大漠飞沙)回复于 2002-03-05 21:14:03 得分 0
好像不行(不是非常确定)。为什么要这样做?Top
3 楼awen800()回复于 2002-03-05 22:11:40 得分 20
www.csharphelp.com有相关的文章Top
4 楼jhnhu(玩的就是技术)回复于 2002-03-05 22:35:27 得分 20
从DataGridColumnStyle继承,自己写,系统只提供了TextBoxStyle。
asp.net的就方便了,用个template就可以了。
刚学到的,还没研究。不过client一般不用这种专业的grid给客户操作。Top
5 楼awen800()回复于 2002-03-06 15:15:55 得分 0
肯定是行的,从DataGridColumnStyle继承当然可以。
我正在尝试中......Top
6 楼nikita_win(百年)回复于 2002-03-06 16:19:30 得分 0
PL,,,,,,,,,,,,,,,,,,,,,Top
7 楼awen800()回复于 2002-03-06 22:14:12 得分 0
我已有了DataGridComboBoxColumn的源程序,是VB.net写的
我正在消化中,等我彻底弄清楚了,我会将之改写成C#, 有哪位需要的留个mail, 适当给些分就行了。Top
8 楼damekuler(damekuler)回复于 2002-03-07 08:35:58 得分 10
awen800() 给我发一份吧,分没问题!damekuler@msn.comTop
9 楼awen800()回复于 2002-03-07 12:25:09 得分 0
to damekuler(damekuler);
我还在整理改写中,明天应该可以完成初稿,到时我mail给你。Top
10 楼ColorSM()回复于 2002-03-07 12:59:06 得分 10
我也想要。
谢谢
ColorSM@163.net
Top
11 楼yuechang(昌昌)回复于 2002-03-07 13:05:34 得分 20
不知道gridcolumstyle下的format管不管用,对了awen800给我也看看好么
yuechang@263.netTop
12 楼reanna(蕾安娜)回复于 2002-03-07 17:15:28 得分 0
www.csharphelp.com里的确有相关的文章<playing with datagrid>而且经过修改已经能运行了。Top
13 楼reanna(蕾安娜)回复于 2002-03-07 17:18:36 得分 0
//include all the required namespaces
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Xml;
namespace Test
{
public class TestDataGrid : System.Windows.Forms
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.Windows.Forms.ComboBox cmbFunctionArea;
private DataTable dtblFunctionalArea;
private DataGrid dgdFunctionArea;
/// <summary>
/// public constructor
/// </summary>
public TestDataGrid()
{
//automatically generated by the VS Designer
//creates the object of the above designer variables
InitializeComponent();
PopulateGrid();
}
private void PopulateGrid()
{
//Declare and initialize local variables used
DataColumn dtCol = null;//Data Column variable
string[] arrstrFunctionalArea = null;//string array variable
System.Windows.Forms.ComboBox cmbFunctionArea; //combo box var
DataTable dtblFunctionalArea;//Data Table var
//Create the combo box object and set its properties
cmbFunctionArea = new ComboBox();
cmbFunctionArea.Cursor = System.Windows.Forms.Cursors.Arrow;
cmbFunctionArea.DropDownStyle=System.Windows.Forms.ComboBoxStyle.DropDownList;
cmbFunctionArea.Dock = DockStyle.Fill;
//Event that will be fired when selected index in the combo box is changed
cmbFunctionArea.SelectionChangeCommitted += new EventHandlercmbFunctionArea_SelectedIndexChanged);
//Create the String array object, initialize the array with the column
//names to be displayed
arrstrFunctionalArea = new string [3];
arrstrFunctionalArea[0] = "Functional Area";
arrstrFunctionalArea[1] = "Min";
arrstrFunctionalArea[2] = "Max";
//Create the Data Table object which will then be used to hold
//columns and rows
dtblFunctionalArea = new DataTable ("FunctionArea");
//Add the string array of columns to the DataColumn object
for(int i=0; i< 3;i++)
{
string str = arrstrFunctionalArea[i];
dtCol = new DataColumn(str);
dtCol.DataType = System.Type.GetType("System.String");
dtCol.DefaultValue = "";
dtblFunctionalArea.Columns.Add(dtCol);
}
//Add a Column with checkbox at last in the Grid
DataColumn dtcCheck = new DataColumn("IsMandatory");//create the data //column object with the name
dtcCheck.DataType = System.Type.GetType("System.Boolean");//Set its //data Type
dtcCheck.DefaultValue = false;//Set the default value
dtblFunctionalArea.Columns.Add(dtcCheck);//Add the above column to the //Data Table
//Set the Data Grid Source as the Data Table createed above
dgdFunctionArea.DataSource = dtblFunctionalArea;
//set style property when first time the grid loads, next time onwards it //will maintain its property
if(!dgdFunctionArea.TableStyles.Contains("FunctionArea"))
{
//Create a DataGridTableStyle object
DataGridTableStyle dgdtblStyle = new DataGridTableStyle();
//Set its properties
dgdtblStyle.MappingName = dtblFunctionalArea.TableName;//its table name of dataset
dgdFunctionArea.TableStyles.Add(dgdtblStyle);
dgdtblStyle.RowHeadersVisible = false;
dgdtblStyle.HeaderBackColor = Color.LightSteelBlue;
dgdtblStyle.AllowSorting = false;
dgdtblStyle.HeaderBackColor = Color.FromArgb(8,36,107);
dgdtblStyle.RowHeadersVisible = false;
dgdtblStyle.HeaderForeColor = Color.White;
dgdtblStyle.HeaderFont = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
dgdtblStyle.GridLineColor = Color.DarkGray;
dgdtblStyle.PreferredRowHeight = 22;
dgdFunctionArea.BackgroundColor = Color.White;
//Take the columns in a GridColumnStylesCollection object and set //the size of the
//individual columns
GridColumnStylesCollection colStyle;
colStyle = dgdFunctionArea.TableStyles[0].GridColumnStyles;
colStyle[0].Width = 100;
colStyle[1].Width = 50;
colStyle[2].Width = 50;
colStyle[3].Width = 80;
}
//To add the combo box dynamically to the data grid, you have to take the // Text Box that is present (by default) in the column where u want to add //this combo box (here it is first column i.e. Functional Area).From the //tablestyles of the data grid take the grid column styles of the column //where you want to add the combo box respectively.
DataGridTextBoxColumn dgtb = (DataGridTextBoxColumn)dgdFunctionArea.TableStyles[0].GridColumnStyles[0];
//Add the combo box to the text box taken in the above step
dgtb.TextBox.Controls.Add (cmbFunctionArea);
//Note: After these add the code to fill the details in the grid by //establishing
// connection to the server and writing necessary steps:
}
}//end of the class
}//end of the namespace
Top
14 楼coolicer(酷冰人)回复于 2002-03-07 17:30:58 得分 20
goodTop
15 楼awen800()回复于 2002-03-07 20:15:30 得分 0
我总共在csharphelp上发现了5个不同版本的类似代码。
有好有不好,我在整理中......Top
16 楼confucian(唱反调的男人)回复于 2002-05-30 06:40:57 得分 0
那个源程序是错的
第一个错误
类声明应该为:
public class TestDataGrid : System.Windows.Forms.Form
第二个错误
掉了一个(
:)Top
相关问题
- 如何在DataGrid(Windows Form)的表格中加入ComboBox控件
- CDialogBar中加入ComboBox控件,如何初始化ComboBox控件
- 请教:toolbar控件能加入comboBox吗?
- 如何在DataGrid中加入控件!
- 在web页的DataGrid控件的temploate列中,加入DataGrid子控件,引用DataGrid子控件的属性与值!!!
- comboBox控件
- DATAGRID定制模板中,怎样加入单选列表控件?
- 在网页中加入datagrid控件,页面布局变形
- DataGrid页眉能不能加入按钮控件
- 如何在datagrid里动态加入textbox&drowdownlist等web控件?Thanks!




