Results 1 to 3 of 3

Thread: [2005] Data GridView

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    [2005] Data GridView

    Dear All,
    How to populate a datagrid manually.


    I am doing this
    vb Code:
    1. datagridview1.Columns.add("Type","Type)
    2. datagridview1.Columns.add("Age","Age)

    Now I want to fill this column manully.That is not from database.How can I
    Please mark you thread resolved using the Thread Tools as shown

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: [2005] Data GridView

    Best idea is that you make a datatable and add the column in the datatable and then set the grid datasource to that datatable.
    But for your choice you can do like this.


    vb Code:
    1. Me.gridSearch.Columns.Add("Type", "Type")
    2.             For rowIndex As Integer = 0 To Me.gridSearch.RowCount - 1
    3.                 Me.gridSearch.Item("Type", rowIndex).Value = "Shakti"  'Any value
    4.             Next
    5. 'gridSerach is the name of the DataGridView

  3. #3
    Registered User RaviIntegra's Avatar
    Join Date
    Mar 2007
    Location
    Pondicherry, India
    Posts
    125

    Re: [2005] Data GridView

    vb Code:
    1. Private Sub loadGridView()
    2.         'dgview as DatagridView control
    3.         dgView.Columns.Add("clBookName", "Book Name")
    4.         dgView.Columns.Add("clDes", "Description")
    5.         dgView.Columns.Add("clDate", "Date")
    6.         Dim con As New OleDb.OleDbConnection("type your connection string")
    7.         Dim da As New OleDbDataAdapter("type your query", con)
    8.         Dim dt As New DataTable
    9.         da.Fill(dt)
    10.         Dim str() As String = {}
    11.         Dim dr As DataRow
    12.         If dt.Rows.Count > 0 Then
    13.             For Each dr In dt.Rows
    14.                 For col As Integer = 0 To dt.Columns.Count - 1
    15.                     str(col) = dr(col).ToString
    16.                 Next
    17.                 dgView.Rows.Add(str)
    18.             Next
    19.         End If
    20.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width