📄 datagridviewtasks.vb
字号:
'---------------------------------------------------------------------
' This file is part of the Microsoft .NET Framework SDK Code Samples.
'
' Copyright (C) Microsoft Corporation. All rights reserved.
'
' This source code is intended only as a supplement to Microsoft
' Development Tools and/or on-line documentation. See these other
' materials for detailed information regarding Microsoft code samples.
'
' THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'---------------------------------------------------------------------
Imports System.Windows.Forms
Public Class DataGridViewTasks
Inherits DataGridView
Private m_HtImages As New Hashtable()
Private Const c_PriorityImagesPath As String = "Images\"
Private m_ResourceManager As New Resources.ResourceManager("TeamVision.Localize", System.Reflection.Assembly.GetExecutingAssembly())
Sub formatImage(ByVal imageCell As DataGridViewCellFormattingEventArgs)
Dim imageToDraw As Image
Dim priority As String = Me(imageCell.ColumnIndex, imageCell.RowIndex).Value.ToString()
'we're caching the image in a hashtable
If m_HtImages.ContainsKey(priority) Then
imageToDraw = CType(m_HtImages(priority), System.Drawing.Image)
Else
'get the image from disk and cache it
Try
imageToDraw = Image.FromFile(c_PriorityImagesPath & CType(priority, String) & ".gif")
m_HtImages.Add(priority, imageToDraw)
Catch
MessageBox.Show(m_ResourceManager.GetString("The_image_file") & " " & Application.StartupPath & "\" & c_PriorityImagesPath & CType(priority, String) & m_ResourceManager.GetString("gif_was_not_found"), m_ResourceManager.GetString("File_Not_Found"))
LogError.Write(m_ResourceManager.GetString("The_image_file") & " " & Application.StartupPath & "\" & c_PriorityImagesPath & CType(priority, String) & m_ResourceManager.GetString("gif_was_not_found"))
Return
End Try
End If
imageCell.Value = imageToDraw
' For performance set FormatApplied so that formatting happens only once
imageCell.FormattingApplied = True
End Sub
Sub formatDate(ByVal cell As DataGridViewCellFormattingEventArgs)
'globalize for german
If Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName = "de" Then
cell.Value = String.Format("{0:d}", Convert.ToDateTime(cell.Value).ToString("dd/MM/yy"))
Else
cell.Value = String.Format("{0:d}", Convert.ToDateTime(cell.Value))
End If
If Me.Columns(cell.ColumnIndex).Name = "DateDue" Then
cell.CellStyle.ForeColor = Color.Red
End If
cell.FormattingApplied = True
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -