Click here to Skip to main content
15,903,385 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello...
does anyone knows how to add a data to the datagridview column programically..?
please help..thanks...
Posted
Comments
Henry Minute 17-Jan-11 11:54am    
I have edited my answer after your comment.

Assume that the column is called "myColumn".

C#
myDgv.Rows[0].Cells["myColumn"].Value = "hello";


Replace Rows[0] with the number of the row you are interested in.

[EDIT]
VB.NET
Dim str As String = InputBox("Enter new string")
Dim current = DataGridView1.Rows(0).Cells("DataGridViewTextBoxColumn1").Value.ToString()
DataGridView1.Rows(0).Cells("DataGridViewTextBoxColumn1").Value = current & str


I have broken it into two steps but you could do it all in one line.

BTW: Sorry for posting C# code instead of VB before. :)
[/EDIT]
 
Share this answer
 
v2
Comments
jleonorlane 17-Jan-11 11:44am    
thanks..this works but i want from the user input,and then anything that he enter,adds to the datagridview..
here what i've done..but i want it add everytime the user inserts something...
Dim str As String = InputBox("Enter new string")
DataGridView1.Rows(0).Cells("DataGridViewTextBoxColumn1").Value = str
DataGridView1.Columns.Add("myColumnName")
 
Share this answer
 
Comments
Kschuler 18-Jan-11 16:17pm    
oops. I thought the question was just how to add a column to the grid. Totally missed the setting data bit. Sorry.

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