Results 1 to 4 of 4

Thread: Adding a new column in datagrid at runtime?

  1. #1
    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?

  2. #2
    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" );

  3. #3
    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

  4. #4
    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....

Similar Threads

  1. Adding column of numbers with condition in Excel
    By Abbiey in forum Windows Software
    Replies: 4
    Last Post: 08-01-2010, 10:19 PM
  2. Replies: 3
    Last Post: 09-12-2009, 01:11 PM
  3. How to set and hide the Datagrid column in Compact Framework
    By Balgovind in forum Windows Software
    Replies: 2
    Last Post: 09-06-2009, 08:11 PM
  4. Calculating sum of column in datagrid
    By Chrisch in forum Software Development
    Replies: 3
    Last Post: 09-06-2009, 10:07 AM
  5. mysql update column with another column
    By Gunter in forum Software Development
    Replies: 3
    Last Post: 23-05-2009, 09:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,577,078.90087 seconds with 16 queries