[RESOLVED] [2005] Data grid view
Hi
Pls check my code and help how to define the data grid in col.
Code:
Private Sub DesignSearchGrid()
With dgvSearch
.EditMode = DataGridViewEditMode.EditProgrammatically
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.AllowUserToOrderColumns = True
.AllowUserToResizeRows = True
.AllowUserToResizeColumns = True
.MultiSelect = False
.RowHeadersVisible = False
.Location = New Point(9, 43)
.Size = New Size(266, 177)
.ColumnCount = 3
.RowCount = 1
.Columns(0).Name = "EmpCode"
.Columns(0).Width = 70
.Columns(1).Name = "Employee Name"
.Columns(1).Width = 200
.Columns(2).Name = "Date of Birth"
.Columns(2).Width = 100
End With
End Sub
Private Sub PopulateSearchGrid()
Dim DaSearch As SqlDataAdapter
Dim dtSearch As New DataTable
Dim StrQuery As String
Dim iRow As Integer
Try
StrQuery = "SELECT EmployeeMaster.EmpCode, EmployeeMaster.Name as EmpName,EmployeeMaster.DOB as EmpName FROM EmployeeMaster"
DaSearch = New SqlDataAdapter(StrQuery, Conn)
DaSearch.Fill(dtSearch)
For iRow = 0 To dgvSearch.RowCount - 1
dgvSearch.Rows(iRow).Cells(0).Value = dtSearch.Rows.Item("EmpCode")
dgvSearch.Rows(iRow).Cells(0).Value = dtSearch.Rows.Item("EmpName")
dgvSearch.Rows(iRow).Cells(0).Value = dtSearch.Rows.Item("DOB")
Next iRow
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
thanks
Re: [2005] Data grid view
Please explain in brief your question.
Re: [2005] Data grid view
Create a DataGridViewColumn of the appropriate type, e.g. DataGridViewTextBoxColumn, then set its properties and add it to the grid's Columns collection.