我們要實現上圖中的效果,需要如下的操作:
VB: Private Sub TestGridView2_Load(senderAs Object, e As EventArgs)Handles MyBase.Load Dim matTable As New DataTable matTable.Columns.Add("MAT_DESC1", GetType(String)) matTable.Columns.Add("MAT_DESC2", GetType(String)) matTable.Columns.Add("MAT_DESC3", GetType(String)) matTable.Rows.Add() matTable.Rows(0)("MAT_DESC1") = "Vicky的請假" matTable.Rows(0)("MAT_DESC2") = "待審批" matTable.Rows(0)("MAT_DESC3") = "上午11:51" matTable.Rows.Add() matTable.Rows(1)("MAT_DESC1") = "Vicky的請假" matTable.Rows(1)("MAT_DESC2") = "待審批" matTable.Rows(1)("MAT_DESC3") = "2015.09.09" Me.GridView1.DataSource = matTable Me.GridView1.DataBind() End Sub
C#: private void TestGridView2_Load(object sender, EventArgs e) { DataTable matTable = new DataTable(); matTable.Columns.Add("MAT_DESC1", typeof(string)); matTable.Columns.Add("MAT_DESC2", typeof(string)); matTable.Columns.Add("MAT_DESC3", typeof(string)); matTable.Rows.Add(); matTable.Rows[0]["MAT_DESC1"] = "Vicky的請假"; matTable.Rows[0]["MAT_DESC2"] = "待審批"; matTable.Rows[0]["MAT_DESC3"] = "上午11:51"; matTable.Rows.Add(); matTable.Rows[1]["MAT_DESC1"] = "Vicky的請假"; matTable.Rows[1]["MAT_DESC2"] = "待審批"; matTable.Rows[1]["MAT_DESC3"] = "2015.09.09"; this.GridView1.DataSource = matTable; this.GridView1.DataBind(); }
新建MobileForm項,命名為MessageShow2,並拖入一個Image控件和三個Label控件,如圖1
三個Label控件的DisplayMember屬性分別綁定需要顯示的列,如圖2
GridView的Layout屬性,綁定新建的窗體MessageShow2,如圖3
圖1 圖2 圖3