Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Create a DataGridView At RunTime In This DataGridView Also Create a ComboBox when Combobox selected Index Changed How to Define And Where it Define.

MIDL
this.TrGrid = new System.Windows.Forms.DataGridView();
this.TrNo = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.TrName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Arr_Time = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Dep_Time = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Late_Time = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Stat = new System.Windows.Forms.DataGridViewTextBoxColumn();
//this.Pf = new System.Windows.Forms.DataGridViewTextBoxColumn();
//this.Stat = new System.Windows.Forms.DataGridViewComboBoxColumn();
this.Pf = new System.Windows.Forms.DataGridViewComboBoxColumn();
this.Cg = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.TI = new System.Windows.Forms.DataGridViewCheckBoxColumn();


this.TrGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
this.TrGrid.Location = new System.Drawing.Point(0, 30);
this.TrGrid.Name = "TrGrid";
this.TrGrid.Size = new System.Drawing.Size(945, 485);
this.TrGrid.TabIndex = 0;
this.TrGrid.AllowUserToAddRows = false;
this.TrGrid.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.On_Cell_Content_Click);
this.TrGrid.CellClick += new DataGridViewCellEventHandler(this.TrGrid_CellClick);
this.TrGrid.CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.On_Cell_Enter);
this.TrGrid.CellLeave += new System.Windows.Forms.DataGridViewCellEventHandler(this.On_Cell_Leave);
this.TrNo.HeaderText = "Train No";
this.TrNo.Name = "Train No";
this.TrNo.DataPropertyName = "Train_No";
this.TrNo.Width = 90;
//this.TrGrid.Columns.Add(TrNo);
this.TrGrid.Columns.Insert(0,TrNo);

this.TrName.HeaderText = "Tr_Name_Eng";
this.TrName.Name = "Tr_Name_Eng";
this.TrName.DataPropertyName = "Tr_Name_Eng";
this.TrName.Width = 210;
this.TrGrid.Columns.Insert(1,TrName);

this.Arr_Time.HeaderText = "Arr_Time";
this.Arr_Time.Name = "Arr_Time";
this.Arr_Time.DataPropertyName = "Arr_Time";
this.Arr_Time.Width = 80;
this.TrGrid.Columns.Insert(2,Arr_Time);

this.Dep_Time.HeaderText = "Dep_Time";
this.Dep_Time.Name = "Dep_Time";
this.Dep_Time.DataPropertyName = "Dep_Time";
this.Dep_Time.Width = 80;
this.TrGrid.Columns.Insert(3,Dep_Time);

this.Late_Time.HeaderText = "Late_Time";
this.Late_Time.Name = "Late_Time";
this.Late_Time.DataPropertyName = "Late_Time";
this.Late_Time.Width = 80;
this.TrGrid.Columns.Insert(4,Late_Time);

this.Stat.HeaderText = "Status";
this.Stat.Name = "Status";
this.Stat.DataPropertyName = "Status";
//this.Stat.DisplayMember = "Status";
//this.Stat.DataSource = Get_Status();
this.Stat.Width = 200;
this.TrGrid.Columns.Insert(5,Stat);

this.Pf.HeaderText = "Pf_No";
this.Pf.Name = "Pf_No";
this.Pf.DataPropertyName = "Pf_No";
this.Pf.DisplayMember = "Pf_No";
this.Pf.DataSource = get_table();
this.Pf.Width = 50;
this.TrGrid.Columns.Insert(6,Pf);

this.Cg.HeaderText = "Cg_Disp";
this.Cg.Name = "Cg_Disp";
this.Cg.DataPropertyName = "Cg_Disp";
this.Cg.TrueValue = "1";
this.Cg.FalseValue = "0";
this.Cg.Width = 50;
this.TrGrid.Columns.Insert(7, Cg);

this.TI.HeaderText = "Tr_Disp";
this.TI.Name = "Tr_Disp";
this.TI.DataPropertyName = "Tr_Disp";
this.TI.TrueValue = "1";
this.TI.FalseValue = "0";
this.TI.Width = 50;
this.TrGrid.Columns.Insert(8, TI);


this.Controls.Add(TrGrid);
Posted

1 solution

You would be better hooking into the CellValueChanged event.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900