Diễn đàn    Window Form programming    Tạo style trong datagrid của winform

dotnet.vn

74  bài
15-6-2008 8:26:57
Public Shared Function CreateStyle() As DataGridTableStyle
Dim mStyle As New DataGridTableStyle
With mStyle
HeaderFont = New Font("Arial", 9, FontStyleBold)
HeaderBackColor = ColorightBlue
AlternatingBackColor = ColorCornsilk
PreferredowHeight = 24
AllowSorting = True
End With

eturn mStyle
End Function
Public Shared Function CreateCollumnTextBoxStyle(ByVal mapname As String, _
ByVal header As String, ByVal wid As Integer, ByVal nulltext As String, _
ByVal align As HorizontalAlignment)

Dim colStyle As New DataGridTextBoxColumn
With colStyle
MappingName = mapname
HeaderText = header
Width = wid
NullText = nulltext
Alignment = align
End With

eturn colStyle
End Function
Public Shared Function CreateCollumnCheckBoxStyle(ByVal mapname As String, _
ByVal header As String, ByVal wid As Integer)

Dim colStyle As New DataGridBoolColumn
With colStyle
MappingName = mapname
HeaderText = header
Width = wid
End With

eturn colStyle
End Function
 

dotnet.vn

74  bài
15-6-2008 8:27:55
Để hiển thị nó lên dùng cái này

Private Sub FormatGrid()
Dim style As New DataGridTableStyle
style = USF.CreateStyle()

Dim colStyle1 As New DataGridTextBoxColumn
colStyle1 = USF.CreateCollumnTextBoxStyle("Ten_khoa", "Khoa", 80, "", HorizontalAlignment.Left)
Dim colStyle2 As New DataGridTextBoxColumn
colStyle2 = USF.CreateCollumnTextBoxStyle("Ma_gv", "Mã GV", 50, "", HorizontalAlignment.Left)
Dim colStyle3 As New DataGridTextBoxColumn
colStyle3 = USF.CreateCollumnTextBoxStyle("Ho_ten", "Tên GV", 160, "", HorizontalAlignment.Left)

style.GridColumnStyles.AddRange(New DataGridColumnStyle() {colStyle1, colStyle2, colStyle3})
dg.TableStyles.Add(style)
End Sub
 

dotnet.vn

74  bài
15-6-2008 8:29:11
Cái formảtgid chỉ cần dùng 1 lần đầu tiên khi form load, còn muốn hiển thị lại dữ liệu cũng như lần đầu hiển thị dữ liệu khi form load thì dùng cái này

Private Sub Reload()
Try
Dim strSQL As String = "SELECT GIAO_VIEN.*, KHOA.Ten_khoa " _
+ " FROM GIAO_VIEN INNER JOIN " _
+ " KHOA ON GIAO_VIEN.ID_khoa = KHOA.ID_khoa" _
+ " ORDER BY Ho_ten"
Dim dt As DataTable = UDB.SelectTable(strSQL)

dt.DefaultView.AllowDelete = False
dt.DefaultView.AllowEdit = False
dt.DefaultView.AllowNew = False
dg.DataSource = dt.DefaultView
Catch ex As Exception
UCommon.ThongBao(ex.Message)
End Try
End Sub
 

dotnet.vn

74  bài
15-6-2008 8:30:4
Muốn moi dữ liệu mỗi khi bấm vào 1 dòng nào đó của datagrid ra thì dùng cái hàm này
------------------
Private Sub SetUI(ByVal idx As Integer)
Try
Dim dv As DataView = dg.DataSource
Me.ID_gv = CInt(dv(idx)("ID_gv"))
txtHoTen.Text = dv(idx)("Ho_ten").ToString()
txtMa.Text = dv(idx)("Ma_gv").ToString()
dtpNgaysinh.Value = CDate(dv(idx)("Ngay_sinh"))
txtQue.Text = dv(idx)("Que_quan").ToString()
txtTen.Text = dv(idx)("Ten").ToString()
cboBomon.SelectedValue = CInt(dv(idx)("ID_bm"))
cboCapbac.SelectedValue = CInt(dv(idx)("ID_capbac"))
cboChucdanh.SelectedValue = CInt(dv(idx)("ID_chucdanh"))
cboChucvu.SelectedValue = CInt(dv(idx)("ID_chucvu"))
cboDantoc.SelectedValue = CInt(dv(idx)("ID_dantoc"))
cboHocham.SelectedValue = CInt(dv(idx)("ID_hocham"))
cboHocvi.SelectedValue = CInt(dv(idx)("ID_hocvi"))
cboKhoa.SelectedValue = CInt(dv(idx)("ID_khoa"))
If (CBool(dv(idx)("Nam")) = True) Then
radNam.Checked = True
Else
radNu.Checked = True
End If
Catch ex As Exception
End Try
End Sub

-----------------
và đây nữa
-----------------
Private Sub dg_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dg.CurrentCellChanged
btnThem.Enabled = False
Dim idx As Integer = dg.CurrentRowIndex
If idx < 0 Then Return
Me.SetUI(idx)
End Sub
--------------------
tý quên
 

1  bài
11-10-2008 1:34:49
 

25  bài
16-10-2008 19:37:27
hì hì !! xin lỗi chút nha !! trên thực tế ở phần properties nó cho phép chỉnh sữa lưới của win form hay lưới của web rồi !!! chẳng qua do mọi người ko chịu tìm hiểu có video hướng dẫn nhưng bằng english để bữa nào rảnh nén lại gửi cho mọi người coi !!
---
 

Thiên thần Kaka

37  bài
7-12-2008 16:7:55
nén luôn đê toàn thấy nói chả thấy làm gì ?
---
 
Tên file Mô tả chi tiết Ngày
NWeb.zip (1) Module đơn giản Newsweb trên Dotnetnuke v10.x.x.x10/18/2025 8:08:11 AM
vspforum.zip (11) Ma nguon vspforum ngay xua4/18/2023 6:38:37 AM
pdfjs.rar (2) pdfjs 2017 : hiển thị tốt trên iphone 11, 12, 13 không lỗi, bản 2012 sẽ lỗi trên iphone6/21/2022 11:52:48 AM
pdfjs2.rar (2) Xem file pdf bằng viewer.hml cua pdfjs (thư viện chuẩn mozilla) 2012. https://mozilla.github.io/pdf.js/getting_started/#download có thể download bản prebuild tại đây6/21/2022 11:52:04 AM
runner.zip (0) using three.js, orbitcontrol to view an object move random on map. Di chuyển 1 đồ vật ngẫu nhiên trên bản đồ, sử dụng với demo nhân viên di chuyển trong văn phòng. Toàn js download về là chạy12/5/2019 5:55:14 PM
gmap.zip (1) google map + marker7/17/2019 2:25:05 PM
vinsmarthomeservice.zip (1) java post json to api, use AsyncTask, event listener7/9/2019 5:00:10 PM
fblogin.zip (0) Login facebook bang javascript SDK7/9/2019 9:16:37 AM
autocomplete-location.zip (2) autocomplete location geo from google place, html + js7/4/2019 4:37:55 PM
WebAPI.zip (8) api for android access db (v1.0.0)7/4/2019 9:14:17 AM