Dear All,
How to populate a datagrid manually.
I am doing this
vb Code:
datagridview1.Columns.add("Type","Type) datagridview1.Columns.add("Age","Age)
Now I want to fill this column manully.That is not from database.How can I
Printable View
Dear All,
How to populate a datagrid manually.
I am doing this
vb Code:
datagridview1.Columns.add("Type","Type) datagridview1.Columns.add("Age","Age)
Now I want to fill this column manully.That is not from database.How can I
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:
Me.gridSearch.Columns.Add("Type", "Type") For rowIndex As Integer = 0 To Me.gridSearch.RowCount - 1 Me.gridSearch.Item("Type", rowIndex).Value = "Shakti" 'Any value Next 'gridSerach is the name of the DataGridView
vb Code:
Private Sub loadGridView() 'dgview as DatagridView control dgView.Columns.Add("clBookName", "Book Name") dgView.Columns.Add("clDes", "Description") dgView.Columns.Add("clDate", "Date") Dim con As New OleDb.OleDbConnection("type your connection string") Dim da As New OleDbDataAdapter("type your query", con) Dim dt As New DataTable da.Fill(dt) Dim str() As String = {} Dim dr As DataRow If dt.Rows.Count > 0 Then For Each dr In dt.Rows For col As Integer = 0 To dt.Columns.Count - 1 str(col) = dr(col).ToString Next dgView.Rows.Add(str) Next End If End Sub