突出显示vb.net ms访问中的网格视图行 [英] Highlight Grid view rows in vb.net ms access

查看:58
本文介绍了突出显示vb.net ms访问中的网格视图行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
我正在vb.net和MS Access(后端)中开发Windows应用程序.
其中我有两个表,第一个是StudentInfo表,第二个是出勤表.
在studentinfo表中存储了所有学生记录,但是在出勤表中仅显示了学生的姓名和卷名.已存储.
出勤后,我想在Data GridView中显示所有存储在studentinfo表中的记录,并仅突出显示出勤表中以不同颜色显示的那些记录.
我已经完成了50%的工作,即在数据网格视图中显示来自studentinfo表的所有记录.

Hello Friends,
I am developing a windows application in vb.net and MS Access (back end)
in which i have two tables 1st is StudentInfo table and Second is attendance table.
in studentinfo table all the students records stored, but in attendance table only present students name and roll no. stored.
after taking attendance i want to show all records in Data GridView which store in studentinfo table and Highlight only those records which are present in attendance table with different colors.
I have done 50% job i.e. show all records from studentinfo table in data grid view.

<pre lang="vb">

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim da As OleDbDataAdapter
Dim str As String
Dim icount As Integer

Private Sub filldata()
        cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= SRS.mdb;")
        cn.Open()
        
        da = New OleDbDataAdapter("SELECT * FROM StudentInfo", cn)
        Dim dt As New DataTable("StudentInfo")
        da.Fill(dt)
        DataGridView1.DataSource = dt
    End Sub



如何在数据网格视图中突出显示考勤表记录.
请记住,我将VB.net用作前端,将MS Access 2003用作后端.
谢谢



How can i highlight attendance tables records in data grid view.
Please Remember i use VB.net as front end and MS Access 2003 as back end.
Thanks

推荐答案

尝试一下,看看是否可行.我不使用数据集.
Try this and see if it works. I don''t use DataSets.
<pre lang="vb">Private Sub LoadGrid()<br />
    Try<br />
        Dim oODBCConnection As Odbc.OdbcConnection<br />
        Dim sConnString As String = "Driver={Microsoft Access Driver (*.mdb)};Dbq=SRS.mdb;"<br />
        Dim comm As Odbc.OdbcCommand<br />
        oODBCConnection = New Odbc.OdbcConnection(sConnString)<br />
        oODBCConnection.Open()<br />
        Dim dr As Odbc.OdbcDataReader<br />
<br />
        Dim sql As String<br />
        Dim rownum as Integer = 0<br />
        sql = "SELECT * FROM StudentInfo"<br />
        comm = New Odbc.OdbcCommand(sql, oODBCConnection)<br />
        dr = comm.ExecuteReader()<br />
        With Me.DataGridView.Rows<br />
            .Clear()<br />
            While dr.Read()<br />
                .Add(dr!field1, _<br />
                    dr!StudentIsPresentTableFieldName, _<br />
                    dr!field3)<br />
                '' Here is where the checking is accomplished,<br />
                '' Look through the new row added and highlight<br />
                '' the row that meets the proper conditions.<br />
                With Me.DataGridView.Rows(rownum)<br />
                    If .Cell(1).Value = 1 Then<br />
                        .DefaultCellStyle.BackColor = Color.Yellow<br />
                        .DefaultCellStyle.SelectionBackColor = Color.Yellow<br />
                    ElseIf .Cell(1).Value = 2 then<br />
                        .DefaultCellStyle.BackColor = Color.Silver<br />
                        .DefaultCellStyle.SelectionBackColor = Color.Silver<br />
                    End If<br />
                End With<br />
                rownum = rownum + 1<br />
            End While<br />
        End With<br />
<br />
        dr.Close()<br />
        oODBCConnection.Close()<br />
        comm.Dispose()<br />
        oODBCConnection.Dispose()<br />
    Catch ex As Exception<br />
        MessageBox.Show("FAILED TO LOAD GRID: " & ex.Message)<br />
    End Try<br />
End Sub</pre><br />


这篇关于突出显示vb.net ms访问中的网格视图行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆