1
我目前遇到有關在數據網格中查看數據的問題。我能夠在datagridview中顯示它,但問題是數據不可見。它只在選中時變得可見。只有選定的單元格在數據網格中可見
這裏的輸出顯示:
我只是想知道我可以添加什麼命令,我的代碼,以使其可見。謝謝。這裏是我的代碼:
Imports System.Data.OleDb
Public Class ProfessorList
Private Sub ProfessorList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dgvView()
End Sub
Private Sub dgvView()
Using conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database.accdb;")
conn.Open()
Dim command As New OleDbCommand("SELECT * from ProfessorListTable", conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
dgvProfessorList.DataSource = dt
addDGV()
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
End Sub
Public Sub addDGV()
With dgvProfessorList
.Columns(0).Width = 100
.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(1).Width = 150
.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
.Columns(2).Width = 150
.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
.Columns(3).Width = 40
.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
.Columns(4).Width = 100
.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
.Columns(5).Width = 110
.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
End With
End Sub
Private Sub btnFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFilter.Click
Try
Using conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database.accdb;")
conn.Open()
Dim query As String = "SELECT * FROM ProfessorListTable "
Dim where As String = ""
If rbEngineering.Checked Then where &= " Department = 'Engineering' AND"
If rbArchitecture.Checked Then where &= " Department = 'Architecture' AND"
If rbTechnology.Checked Then where &= " Department = 'Technology' AND"
If where <> "" Then query &= "WHERE" & where
query = query.Substring(0, Len(query) - 3)
Dim cmd As New OleDbCommand(query, conn)
Dim adapter As New OleDbDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = cmd
adapter.Fill(dt)
dgvProfessorList.DataSource = dt
addDGV()
adapter.Dispose()
cmd.Dispose()
conn.Close()
End Using
Catch
MsgBox("Please select Department to filter!", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub btnProfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProfile.Click
With Profile
.lblIDnum.Text = dgvProfessorList.CurrentRow.Cells(0).Value
.lblFirstName.Text = dgvProfessorList.CurrentRow.Cells(2).Value
.lblInitial.Text = dgvProfessorList.CurrentRow.Cells(3).Value
.lblLastName.Text = dgvProfessorList.CurrentRow.Cells(1).Value
.lblDept.Text = dgvProfessorList.CurrentRow.Cells(4).Value
.lblYearEmployed.Text = dgvProfessorList.CurrentRow.Cells(5).Value
.ShowDialog()
End With
End Sub
End Class
你改變你的datagridView的背景顏色..檢查你的數據gridview屬性。 – Unknownymous