//TO deepbluefly(苍鹰): //新建一个项目,再在form1删除所有代码,后将这两个贴的内容合到一起粘到Form1中。专为你做的测试了,算是不错了吧,以后再也不答这方面的问题了,注释就不写了。烦人!晚了,我自己还要完成一个模块,才安心睡。。顺愿你学会! //This class describes the method to add any controls of your choice to the data // grid control.
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Text; using System.Xml; using System.Data.SqlClient; namespace PWDgFunctionalArea { public class TestDataGrid : System.Windows.Forms.Form { /// <summary> /// Required designer variables /// </summary> private System.Windows.Forms.ComboBox comboControl; private DataTable dataTable; private System.Windows.Forms.Button button1; private DataGrid.HitTestInfo hitTestGrid; private System.Windows.Forms.DataGrid datagrid1; private DataGridTextBoxColumn datagridtextBox; private string[] arrstr ; /// <summary> /// public constructor /// </summary> public TestDataGrid() { InitializeComponent(); //Method to create the customized data grid CreateGrid(); } /// <summary> /// 清理所有正在使用的资源。 /// </summary> static void Main() { Application.Run(new TestDataGrid()); } /// <summary> /// Method defn to create the Data Grid using data table /// </summary> private void CreateGrid() { //Declare and initialize local variables used DataColumn dtCol = null;//Data Column variable
//Create the String array object, initialize the array with the column //names to be displayed arrstr = new string [3]; arrstr[0] = "Control Name"; arrstr[1] = "Control"; arrstr[2] = "Description";
//Create the Data Table object which will then be used to hold //columns and rows dataTable = new DataTable("Controls"); //Add the string array of columns to the DataColumn object for(int i=0; i< 3;i++) { string str = arrstr[i]; dtCol = new DataColumn(str); dtCol.DataType = System.Type.GetType("System.String"); dtCol.DefaultValue = ""; dataTable.Columns.Add(dtCol); } DataRow newRow1; newRow1=dataTable.NewRow (); newRow1["Control Name"]="ComboBox"; newRow1["Control"]="请单击这里看下拉的效果!!!"; dataTable.Rows.Add(newRow1); newRow1=dataTable.NewRow (); newRow1["Control Name"]="DateTime"; dataTable.Rows.Add(newRow1); newRow1=dataTable.NewRow (); newRow1["Control Name"]="CheckBox"; dataTable.Rows.Add(newRow1);
//Set the Data Grid Source as the Data Table created above datagrid1.DataSource = dataTable;
//set style property when first time the grid loads, next time onwards it //will maintain its property if(!datagrid1.TableStyles.Contains("Controls")) { //Create a DataGridTableStyle object DataGridTableStyle dgdtblStyle = new DataGridTableStyle(); //Set its properties dgdtblStyle.MappingName = dataTable.TableName;//its table name of dataset datagrid1.TableStyles.Add(dgdtblStyle); dgdtblStyle.RowHeadersVisible = false; dgdtblStyle.HeaderBackColor = Color.LightSteelBlue; dgdtblStyle.AllowSorting = false; dgdtblStyle.HeaderBackColor = Color.Navy;//.FromArgb(8,36,107); 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; datagrid1.BackgroundColor = Color.White; //Take the columns in a GridColumnStylesCollection object and set //the size of the //individual columns GridColumnStylesCollection colStyle; colStyle = datagrid1.TableStyles[0].GridColumnStyles; colStyle[0].Width = 97; colStyle[1].Width = 220; colStyle[2].Width = 150; } //Take the text box from the second column of the grid where u will be adding the controls of your choice datagridtextBox = (DataGridTextBoxColumn)datagrid1.TableStyles[0].GridColumnStyles[1]; datagridtextBox.TextBox.GotFocus += new EventHandler(this.dgdFunctionArea_GotFocus); }
/// <summary> /// Method defn to connect to the data base and then load the data grid /// </summary>
private void LoadGrid() { MessageBox.Show ("如果要读数库,请改到下面的代码!!"); return; try { //Establish the connection to the data base and open it SqlConnection sqlConn = new SqlConnection("user id=sa;password=;initial catalog=northwind;data source=mySQLServer;Connect Timeout=30"); //*-Pass the required details sqlConn.Open();
//create the sql command object and set its command type to execute the sql query to get the results SqlCommand sc = new SqlCommand(); sc.Connection = sqlConn; sc.CommandType = CommandType.Text; sc.CommandText = "SELECT * FROM test";
//create the data set object to be used to fill the data grid with the data DataSet ds = new DataSet(); //Create the sql adapter that will be used to fill the data set created above SqlDataAdapter myReader = new SqlDataAdapter(sc); myReader.Fill(ds); //Fill the rows in the grid for(int i =0;i<ds.Tables[0].Rows.Count;i++) { dataTable.LoadDataRow(arrstr,true); datagrid1[i,0] = ds.Tables[0].Rows[i].ItemArray[0].ToString(); datagrid1[i,1] = ds.Tables[0].Rows[i].ItemArray[1].ToString(); datagrid1[i,2] = ds.Tables[0].Rows[i].ItemArray[2].ToString(); } } catch(Exception) {} } /// <summary> /// to create the controls /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.datagrid1 = new System.Windows.Forms.DataGrid(); ((System.ComponentModel.ISupportInitialize)(this.datagrid1)).BeginInit(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(246, 176); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(96, 26); this.button1.TabIndex = 9; this.button1.Text = "Load Grid"; this.button1.Click += new System.EventHandler(this.button1_Click); // // datagrid1 // this.datagrid1.BackgroundColor = System.Drawing.SystemColors.ActiveCaptionText; this.datagrid1.CaptionVisible = false; this.datagrid1.DataMember = ""; this.datagrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.datagrid1.Location = new System.Drawing.Point(10, 19); this.datagrid1.Name = "datagrid1"; this.datagrid1.PreferredRowHeight = 20; this.datagrid1.ReadOnly = true; this.datagrid1.Size = new System.Drawing.Size(604, 148); this.datagrid1.TabIndex = 10; this.datagrid1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dgd_MouseDown); // // TestDataGrid // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(624, 209); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.datagrid1, this.button1}); this.Name = "TestDataGrid"; this.Load += new System.EventHandler(this.TestDataGrid_Load); ((System.ComponentModel.ISupportInitialize)(this.datagrid1)).EndInit(); this.ResumeLayout(false); }
/// <summary> /// The main entry point for the application. /// </summary> [STAThread]
/// <summary> /// Method defn to add the control of your choice to the data grid /// </summary> /// <param name="o"></param> /// <param name="e"></param> private void dgdFunctionArea_GotFocus(object o, EventArgs e) { //Create the combo control to be added and set its properties comboControl = new ComboBox(); comboControl.Cursor = System.Windows.Forms.Cursors.Arrow; comboControl.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown; comboControl.Dock = DockStyle.Fill; comboControl.Items.AddRange(new string[5]{"测试这里!!!!哈哈哈","Information Technology","Computer Science","Bio Technology","Electrical Engg"}); //Create the date time picker control to be added and set its properties DateTimePicker dtp = new DateTimePicker(); dtp.Dock = DockStyle.Fill; dtp.Cursor = Cursors.Arrow; //Create the check box control to be added and set its properties CheckBox chk = new CheckBox(); chk.Dock = DockStyle.Fill; chk.Cursor = Cursors.Arrow; //Create the radio button control to be added and set its properties RadioButton rb = new RadioButton(); rb.Dock = DockStyle.Fill; rb.Cursor = Cursors.Arrow;
//Add the controls to the respective columns in the data grid for(int i = 0 ;i < dataTable.Rows.Count ; i++) { //if the data in the first column is date time, add a date time control to the grid if(datagrid1[i,0].ToString().Equals("DateTime") && hitTestGrid != null && hitTestGrid.Row == i) { datagridtextBox.TextBox.Controls.Add(dtp); comboControl.SendToBack(); chk.SendToBack(); rb.SendToBack(); dtp.BringToFront(); } //if the data in the first column is combo box, add a combo box control to the grid else if(datagrid1[i,0].ToString().Equals("ComboBox") && hitTestGrid != null && hitTestGrid.Row == i) { datagridtextBox.TextBox.Controls.Add(comboControl); chk.SendToBack(); dtp.SendToBack(); rb.SendToBack(); comboControl.BringToFront(); comboControl.Text =datagrid1[datagrid1.CurrentCell.RowNumber,datagrid1.CurrentCell.ColumnNumber].ToString (); comboControl.TextChanged += new EventHandler(this.comboControl_TextChanged); } //if the data in the first column is check box, add a check box control to the grid else if(datagrid1[i,0].ToString().Equals("CheckBox") && hitTestGrid != null && hitTestGrid.Row == i) { datagridtextBox.TextBox.Controls.Add(chk); comboControl.SendToBack(); dtp.SendToBack(); rb.SendToBack(); chk.BringToFront(); } //if the data in the first column is radio button, add a radio button control to the grid if(datagrid1[i,0].ToString().Equals("Radio Button") && hitTestGrid != null && hitTestGrid.Row == i) { datagridtextBox.TextBox.Controls.Add(rb); comboControl.SendToBack(); chk.SendToBack(); dtp.SendToBack(); rb.BringToFront(); } datagridtextBox.TextBox.BackColor = Color.White; } } private void comboControl_TextChanged(object sender, System.EventArgs e) { datagrid1[datagrid1.CurrentCell.RowNumber,datagrid1.CurrentCell.ColumnNumber]=comboControl.Text; //将改变的值传回DATAGRID中. } /// <summary> /// MEthod defn when load grid button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, System.EventArgs e) { try { LoadGrid(); } catch{} }
/// <summary> /// Mouse down event of the data grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgd_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { //take the hit test that will be used to identify which row has been clicked hitTestGrid = datagrid1.HitTest(e.X,e.Y); } private void TestDataGrid_Load(object sender, System.EventArgs e) {
怎么设置
说句实话,微软的GRID垃圾不如!微软的工程师如果不是有意不加强GRID功能就是一班猪!几代的GRID都没有给我们一个好一点的希望。
不足之处就不一一数落,越想越气。。
private DataGridTextBoxColumn datagridtextBox;
datagridtextBox = (DataGridTextBoxColumn)dg1.TableStyles[0].GridColumnStyles[4]; //指明第几列!
datagridtextBox4.TextBox.GotFocus += new EventHandler(this.dgdFunctionArea_GotFocus);
private void dgdFunctionArea_GotFocus(object o, EventArgs e)
{
comboControl = new ComboBox();
comboControl.Cursor= System.Windows.Forms.Cursors.Arrow;
comboControl.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList ;
comboControl.Dock = DockStyle.Fill ;
comboControl.Items.AddRange(new string[6]{"大老虎","可爱的龙","猪头","死老鼠","鸡婆","马"});
datagridtextBox.TextBox.Controls.Add(comboControl);
comboControl.Text =dg1[dg1.CurrentCell.RowNumber,datagrid1.CurrentCell.ColumnNumber].ToString ();//将GRID的值赋给下拉框。
comboControl.BringToFront();
comboControl.SelectedIndexChanged +=new EventHandler(this.comboControl_SelectedIndexChanged);//增加一事件,好让选择到的值能返回到GRID中。
}
//如何返回值就你自己在这里写了。
private void comboControl_SelectedIndexChanged(object sender, System.EventArgs e)
{
datagrid1[datagrid1.CurrentCell.RowNumber,datagrid1.CurrentCell.ColumnNumber]=comboControl.Text; //将改变的值传回DATAGRID中.
}
private ComboBox comboControl;
private DataGridTextBoxColumn datagridtextBox;
datagridtextBox = (DataGridTextBoxColumn)dg1.TableStyles[0].GridColumnStyles[4]; //指明第几列!
datagridtextBox.TextBox.GotFocus += new EventHandler(this.dgdFunctionArea_GotFocus);
private void dgdFunctionArea_GotFocus(object o, EventArgs e)
{
comboControl = new ComboBox();
comboControl.Cursor= System.Windows.Forms.Cursors.Arrow;
comboControl.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList ;
comboControl.Dock = DockStyle.Fill ;
comboControl.Items.AddRange(new string[6]{"大老虎","可爱的龙","猪头","死老鼠","鸡婆","马"});
datagridtextBox.TextBox.Controls.Add(comboControl);
comboControl.Text =dg1[dg1.CurrentCell.RowNumber,datagrid1.CurrentCell.ColumnNumber].ToString ();//将GRID的值赋给下拉框。
comboControl.BringToFront();
comboControl.SelectedIndexChanged +=new EventHandler(this.comboControl_SelectedIndexChanged);//增加一事件,好让选择到的值能返回到GRID中。
}
//如何返回值就你自己在这里写了。
private void comboControl_SelectedIndexChanged(object sender, System.EventArgs e)
{ datagrid1[datagrid1.CurrentCell.RowNumber,datagrid1.CurrentCell.ColumnNumber]=comboControl.Text; //将改变的值传回DATAGRID中.
}
//新建一个项目,再在form1删除所有代码,后将这两个贴的内容合到一起粘到Form1中。专为你做的测试了,算是不错了吧,以后再也不答这方面的问题了,注释就不写了。烦人!晚了,我自己还要完成一个模块,才安心睡。。顺愿你学会!
//This class describes the method to add any controls of your choice to the data
// grid control.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Xml;
using System.Data.SqlClient;
namespace PWDgFunctionalArea
{
public class TestDataGrid : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variables
/// </summary>
private System.Windows.Forms.ComboBox comboControl;
private DataTable dataTable;
private System.Windows.Forms.Button button1;
private DataGrid.HitTestInfo hitTestGrid;
private System.Windows.Forms.DataGrid datagrid1;
private DataGridTextBoxColumn datagridtextBox;
private string[] arrstr ; /// <summary>
/// public constructor
/// </summary>
public TestDataGrid()
{
InitializeComponent();
//Method to create the customized data grid
CreateGrid();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
static void Main()
{
Application.Run(new TestDataGrid());
}
/// <summary>
/// Method defn to create the Data Grid using data table
/// </summary>
private void CreateGrid()
{
//Declare and initialize local variables used
DataColumn dtCol = null;//Data Column variable
//Create the String array object, initialize the array with the column
//names to be displayed
arrstr = new string [3];
arrstr[0] = "Control Name";
arrstr[1] = "Control";
arrstr[2] = "Description";
//Create the Data Table object which will then be used to hold
//columns and rows
dataTable = new DataTable("Controls");
//Add the string array of columns to the DataColumn object
for(int i=0; i< 3;i++)
{
string str = arrstr[i];
dtCol = new DataColumn(str);
dtCol.DataType = System.Type.GetType("System.String");
dtCol.DefaultValue = "";
dataTable.Columns.Add(dtCol);
}
DataRow newRow1;
newRow1=dataTable.NewRow ();
newRow1["Control Name"]="ComboBox";
newRow1["Control"]="请单击这里看下拉的效果!!!";
dataTable.Rows.Add(newRow1);
newRow1=dataTable.NewRow ();
newRow1["Control Name"]="DateTime";
dataTable.Rows.Add(newRow1);
newRow1=dataTable.NewRow ();
newRow1["Control Name"]="CheckBox";
dataTable.Rows.Add(newRow1);
//Set the Data Grid Source as the Data Table created above
datagrid1.DataSource = dataTable;
//set style property when first time the grid loads, next time onwards it //will maintain its property
if(!datagrid1.TableStyles.Contains("Controls"))
{
//Create a DataGridTableStyle object
DataGridTableStyle dgdtblStyle = new DataGridTableStyle();
//Set its properties
dgdtblStyle.MappingName = dataTable.TableName;//its table name of dataset
datagrid1.TableStyles.Add(dgdtblStyle);
dgdtblStyle.RowHeadersVisible = false;
dgdtblStyle.HeaderBackColor = Color.LightSteelBlue;
dgdtblStyle.AllowSorting = false;
dgdtblStyle.HeaderBackColor = Color.Navy;//.FromArgb(8,36,107);
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;
datagrid1.BackgroundColor = Color.White; //Take the columns in a GridColumnStylesCollection object and set //the size of the
//individual columns
GridColumnStylesCollection colStyle;
colStyle = datagrid1.TableStyles[0].GridColumnStyles;
colStyle[0].Width = 97;
colStyle[1].Width = 220;
colStyle[2].Width = 150;
}
//Take the text box from the second column of the grid where u will be adding the controls of your choice
datagridtextBox = (DataGridTextBoxColumn)datagrid1.TableStyles[0].GridColumnStyles[1];
datagridtextBox.TextBox.GotFocus += new EventHandler(this.dgdFunctionArea_GotFocus);
}
/// <summary>
/// Method defn to connect to the data base and then load the data grid
/// </summary>
{
MessageBox.Show ("如果要读数库,请改到下面的代码!!");
return;
try
{
//Establish the connection to the data base and open it
SqlConnection sqlConn = new SqlConnection("user id=sa;password=;initial catalog=northwind;data source=mySQLServer;Connect Timeout=30");
//*-Pass the required details
sqlConn.Open();
//create the sql command object and set its command type to execute the sql query to get the results
SqlCommand sc = new SqlCommand();
sc.Connection = sqlConn;
sc.CommandType = CommandType.Text;
sc.CommandText = "SELECT * FROM test";
//create the data set object to be used to fill the data grid with the data
DataSet ds = new DataSet();
//Create the sql adapter that will be used to fill the data set created above
SqlDataAdapter myReader = new SqlDataAdapter(sc);
myReader.Fill(ds); //Fill the rows in the grid
for(int i =0;i<ds.Tables[0].Rows.Count;i++)
{
dataTable.LoadDataRow(arrstr,true);
datagrid1[i,0] = ds.Tables[0].Rows[i].ItemArray[0].ToString();
datagrid1[i,1] = ds.Tables[0].Rows[i].ItemArray[1].ToString();
datagrid1[i,2] = ds.Tables[0].Rows[i].ItemArray[2].ToString();
}
}
catch(Exception)
{}
} /// <summary>
/// to create the controls
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.datagrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.datagrid1)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(246, 176);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(96, 26);
this.button1.TabIndex = 9;
this.button1.Text = "Load Grid";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// datagrid1
//
this.datagrid1.BackgroundColor = System.Drawing.SystemColors.ActiveCaptionText;
this.datagrid1.CaptionVisible = false;
this.datagrid1.DataMember = "";
this.datagrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.datagrid1.Location = new System.Drawing.Point(10, 19);
this.datagrid1.Name = "datagrid1";
this.datagrid1.PreferredRowHeight = 20;
this.datagrid1.ReadOnly = true;
this.datagrid1.Size = new System.Drawing.Size(604, 148);
this.datagrid1.TabIndex = 10;
this.datagrid1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dgd_MouseDown);
//
// TestDataGrid
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(624, 209);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.datagrid1,
this.button1});
this.Name = "TestDataGrid";
this.Load += new System.EventHandler(this.TestDataGrid_Load);
((System.ComponentModel.ISupportInitialize)(this.datagrid1)).EndInit();
this.ResumeLayout(false); }
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
/// <summary>
/// Method defn to add the control of your choice to the data grid
/// </summary>
/// <param name="o"></param>
/// <param name="e"></param>
private void dgdFunctionArea_GotFocus(object o, EventArgs e)
{
//Create the combo control to be added and set its properties
comboControl = new ComboBox();
comboControl.Cursor = System.Windows.Forms.Cursors.Arrow;
comboControl.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
comboControl.Dock = DockStyle.Fill;
comboControl.Items.AddRange(new string[5]{"测试这里!!!!哈哈哈","Information Technology","Computer Science","Bio Technology","Electrical Engg"}); //Create the date time picker control to be added and set its properties
DateTimePicker dtp = new DateTimePicker();
dtp.Dock = DockStyle.Fill;
dtp.Cursor = Cursors.Arrow; //Create the check box control to be added and set its properties
CheckBox chk = new CheckBox();
chk.Dock = DockStyle.Fill;
chk.Cursor = Cursors.Arrow; //Create the radio button control to be added and set its properties
RadioButton rb = new RadioButton();
rb.Dock = DockStyle.Fill;
rb.Cursor = Cursors.Arrow;
//Add the controls to the respective columns in the data grid
for(int i = 0 ;i < dataTable.Rows.Count ; i++)
{
//if the data in the first column is date time, add a date time control to the grid
if(datagrid1[i,0].ToString().Equals("DateTime") && hitTestGrid != null && hitTestGrid.Row == i)
{
datagridtextBox.TextBox.Controls.Add(dtp);
comboControl.SendToBack();
chk.SendToBack();
rb.SendToBack();
dtp.BringToFront();
}
//if the data in the first column is combo box, add a combo box control to the grid
else if(datagrid1[i,0].ToString().Equals("ComboBox") && hitTestGrid != null && hitTestGrid.Row == i)
{
datagridtextBox.TextBox.Controls.Add(comboControl);
chk.SendToBack();
dtp.SendToBack();
rb.SendToBack();
comboControl.BringToFront();
comboControl.Text =datagrid1[datagrid1.CurrentCell.RowNumber,datagrid1.CurrentCell.ColumnNumber].ToString ();
comboControl.TextChanged += new EventHandler(this.comboControl_TextChanged);
}
//if the data in the first column is check box, add a check box control to the grid
else if(datagrid1[i,0].ToString().Equals("CheckBox") && hitTestGrid != null && hitTestGrid.Row == i)
{
datagridtextBox.TextBox.Controls.Add(chk);
comboControl.SendToBack();
dtp.SendToBack();
rb.SendToBack();
chk.BringToFront();
}
//if the data in the first column is radio button, add a radio button control to the grid
if(datagrid1[i,0].ToString().Equals("Radio Button") && hitTestGrid != null && hitTestGrid.Row == i)
{
datagridtextBox.TextBox.Controls.Add(rb);
comboControl.SendToBack();
chk.SendToBack();
dtp.SendToBack();
rb.BringToFront();
}
datagridtextBox.TextBox.BackColor = Color.White;
}
}
private void comboControl_TextChanged(object sender, System.EventArgs e)
{
datagrid1[datagrid1.CurrentCell.RowNumber,datagrid1.CurrentCell.ColumnNumber]=comboControl.Text; //将改变的值传回DATAGRID中.
}
/// <summary>
/// MEthod defn when load grid button is clicked
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e)
{
try
{
LoadGrid();
}
catch{}
}
/// <summary>
/// Mouse down event of the data grid
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgd_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
//take the hit test that will be used to identify which row has been clicked
hitTestGrid = datagrid1.HitTest(e.X,e.Y);
} private void TestDataGrid_Load(object sender, System.EventArgs e)
{
}
}//end of the class
}//end of the namespace
十分感谢!
哈哈 你这可是受人以鱼 不过没有办法 我刚刚学 却要作一个小项目
我认为学习语言 应该分三步 1、学习可视化编程,傻瓜式编程
2、学习其中的代码,理解代码 3、利用可视编程
我在第一个阶段上 觉得有些烦恼 编程似乎缺少创造性的智慧
往往在copy & paste 代码或者模块或者思路
当然也许我处于初学阶段关于揭帖的事情问一下 可不可以给分之后不揭帖
以方便其他人看到该帖 以资学习