Click here to Skip to main content
15,923,083 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do I insert a new column to datagridview from textbox, and place it after the selected column name from combo box in winforms, using C#.net?
Posted
Updated 12-Apr-11 21:16pm
v2
Comments
Dalek Dave 13-Apr-11 3:16am    
Edited for Grammar and Readability.
nsavithal.darsipudi 13-Apr-11 3:21am    
Thank u

1 solution

void MainFormLoad(object sender, EventArgs e)
		{ 
         dataGridView1.ColumnCount=5;
		 dataGridView1.ColumnHeadersVisible=true;
		 DataGridViewCellStyle columnheaderstyle=new DataGridViewCellStyle();
		 columnheaderstyle.BackColor=Color.Beige;
		 dataGridView1.ColumnHeadersDefaultCellStyle=columnheaderstyle;
		 dataGridView1.Columns[3].Name="Date Of Birth";
		 dataGridView1.Columns[3].ValueType=typeof(DateTime);
		 dataGridView1.Columns[3].Width=((dataGridView1.Width)/5)+30;
		 dataGridView1.Columns[1].Name="Employee Id";
		 dataGridView1.Columns[1].ValueType=typeof(string);
		 dataGridView1.Columns[1].Width=(dataGridView1.Width)/5;
		 dataGridView1.Columns[2].Name="Employee name";
		 dataGridView1.Columns[2].ValueType=typeof(string);
		 dataGridView1.Columns[2].Width=(dataGridView1.Width)/5;
		 dataGridView1.Columns[4].Name="Employee Dept";
		 dataGridView1.Columns[4].ValueType=typeof(string);
		 dataGridView1.Columns[4].Width=(dataGridView1.Width)/5;
		 dataGridView1.Columns[1].ReadOnly=false;
		 dataGridView1.Columns[4].ReadOnly=true;
		 dataGridView1.RowHeadersVisible=false;
		 dataGridView1.SelectionMode=DataGridViewSelectionMode.FullRowSelect; 
		}


hope it helps!!
 
Share this answer
 
v2
Comments
Tarun.K.S 13-Apr-11 2:49am    
Uncheck the "Ignore HTML in Text" option while using <pre> tags.
girish sp 13-Apr-11 2:53am    
ok next time onwards..thank you..
Dalek Dave 13-Apr-11 3:16am    
Good Call.
girish sp 13-Apr-11 4:40am    
thank you!!DAVE

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