Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13-02-2009
Member
 
Join Date: Dec 2007
Posts: 38
Adding a new column in datagrid at runtime?

Hello friends!
How can I add new column in datagrid at runtime? Is this possible?
If yes the how?
Reply With Quote
  #2  
Old 13-02-2009
Member
 
Join Date: Jan 2008
Posts: 56
Re: Adding a new column in datagrid at runtime?

Hi, Use the following syntax to add Column at runtime

DataGridView1.Columns.Add ( string ColumnName, string ColumnCaption)

If your Combobox values are unique then use ComboBox selected value as Column name and Caption otherwise choose your own column name and Columncaption can be combobox value. because Columnnames are unique.

Use SelectedIndexChanged event of Combobox to add new Column and
After adding new Column remove it from the Combobox
Ex

Code:
DataGridView1.Columns.Add( "MyColumn", "Column 1" );
Reply With Quote
  #3  
Old 13-02-2009
Member
 
Join Date: Aug 2008
Posts: 40
Re: Adding a new column in datagrid at runtime?

Please have a look at this link & i hope this will help you understand datagrid!

http://www.slxdeveloper.com/devhome/...35&articleid=6

and

http://www.codeproject.com/KB/webfor..._creation.aspx
Reply With Quote
  #4  
Old 13-02-2009
Member
 
Join Date: Feb 2009
Posts: 12
Re: Adding a new column in datagrid at runtime?

I am having a problem of adding a multiple template columns to a datagrid. What i want to do is that whenever the user clicks a button a new template column similar to the one in the existing datagrid is added to that datagrid in runtime.

I am using th code

Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim st As String
        Dim col As New TemplateColumn
        dt = Session("state")
        col = New TemplateColumn
        col = DataGrid1.Columns.Item(3)
        DataGrid1.Columns.AddAt(dt.Columns.Count - 2, col)
        col.HeaderText = "Price " + CStr(dt.Columns.Count - 2) + " (Rs.)"
        st = "Price" + CStr(dt.Columns.Count - 2)
        dt.Columns.Add(st)
        Session("state") = dt
        DataGrid1.DataSource = dt
        DataGrid1.DataBind()
    End Sub
But Whenever i am executing i am finding that only one column is added. The next time i click the button then only the header text is changing and no extra column is added to the datagrid. Please suggest me how to add multiple template column. Also I have another problem....There is a label on the header template. Each time i add a column, I want to change the text of the label. So please help me out....
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Adding a new column in datagrid at runtime?"
Thread Thread Starter Forum Replies Last Post
Adding column of numbers with condition in Excel Abbiey Windows Software 4 08-01-2010 10:19 PM
How to highlight identical cell value of one column in another column? D_chapple Windows Software 3 09-12-2009 01:11 PM
How to set and hide the Datagrid column in Compact Framework Balgovind Windows Software 2 09-06-2009 08:11 PM
Calculating sum of column in datagrid Chrisch Software Development 3 09-06-2009 10:07 AM
mysql update column with another column Gunter Software Development 3 23-05-2009 09:44 AM


All times are GMT +5.5. The time now is 12:35 PM.