Mini Kabibi Habibi
Imports System.Collections
Imports System.ComponentModel
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports DevExpress.XtraBars.Alerter
Imports DevExpress.XtraEditors
Imports DevExpress.XtraBars
Namespace DevExpress.XtraGrid.Demos
''' <summary>
''' Summary description for OutlookStyle.
''' </summary>
Partial Public Class OutlookStyle
Inherits TutorialControl
Public Sub New()
' This call is required by the Windows.Forms Form Designer.
InitializeComponent()
TutorialInfo.WhatsThisCodeFile = "VB\GridMainDemo\Modules\OutlookStyle.vb"
TutorialInfo.WhatsThisXMLFile = "OutlookStyle.xml"
' TODO: Add any initialization after the InitForm call
'<gridControl1>
'~Note: the following properties are set at design time and listed here only for demonstration purposes.
'~gridView1.OptionsView.GroupDrawMode = Views.Grid.GroupDrawMode.Office2003
'~gridView1.OptionsView.ShowGroupedColumns = True
'~gridView1.OptionsView.ShowGroupPanel = False
'~gridView1.OptionsView.ShowVerticalLines = Utils.DefaultBoolean.False
'</gridControl1>
End Sub
Private mTimer As MailTimer
Public Overrides ReadOnly Property ExportView() As DevExpress.XtraGrid.Views.Base.BaseView
Get
Return gridView1
End Get
End Property
Private Sub OutlookStyle_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
gridControl1.DataSource = OutlookData.CreateDataTable()
gridView1.SetRowExpanded(-1, True)
gridView1.SetRowExpanded(-2, True)
mTimer = New MailTimer(TryCast(gridControl1.DataSource, DataTable), alertControl1, Me.FindForm())
OnStyleChanged()
SetAlertControlButtonHint()
End Sub
Private Sub SetAlertControlButtonHint()
alertControl1.Buttons(0).Hint = My.Resources.FlagItem
alertControl1.Buttons(1).Hint = My.Resources.MarkAsRead
alertControl1.Buttons(2).Hint = My.Resources.OpenAttachment
alertControl1.Buttons(3).Hint = My.Resources.DeleteItem
End Sub
Private Sub gridView1_CustomDrawGroupRow(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs) Handles gridView1.CustomDrawGroupRow
Dim info As GridGroupRowInfo = TryCast(e.Info, GridGroupRowInfo)
If info Is Nothing Then
Return
End If
info.GroupText = info.GroupText.Replace("1 " & My.Resources.Items, "1 " & My.Resources.Item)
End Sub
Protected Overrides Sub DoShow()
MyBase.DoShow()
gridControl1.Focus()
mTimer.Start()
End Sub
Protected Overrides Sub DoHide()
mTimer.Stop()
End Sub
#Region "Alerter"
Private Sub alertControl1_ButtonDownChanged(ByVal sender As Object, ByVal e As AlertButtonDownChangedEventArgs) Handles alertControl1.ButtonDownChanged
If e.ButtonName = "Flag" Then
CType(e.Info.Tag, MailData).Flag = If(e.Down, 0, 1)
End If
If e.ButtonName = "Read" Then
CType(e.Info.Tag, MailData).Read = If(e.Down, 1, 0)
End If
End Sub
Private Sub alertControl1_ButtonClick(ByVal sender As Object, ByVal e As AlertButtonClickEventArgs) Handles alertControl1.ButtonClick
Dim data As MailData = TryCast(e.Info.Tag, MailData)
e.AlertForm.OwnerForm.Activate()
If e.ButtonName = "Attachment" Then
e.AlertForm.Close()
XtraMessageBox.Show(FindForm(), "Open attachment dialog.", String.Format("Mail From: {0}", data.From))
End If
If e.ButtonName = "Delete" Then
DeleteItem(e, data)
End If
End Sub
Private Sub OpenItem(ByVal data As MailData)
For i As Integer = 0 To gridView1.RowCount - 1
If data.Row.Equals(gridView1.GetDataRow(i)) Then
gridView1.FocusedRowHandle = i
Exit For
End If
Next i
End Sub
Private Sub DeleteItem(ByVal args As AlertClickEventArgs, ByVal data As MailData)
args.AlertForm.Close()
Try
Dim tbl As DataTable = TryCast(gridControl1.DataSource, DataTable)
tbl.Rows.Remove(data.Row)
gridView1.LayoutChanged()
Catch
End Try
End Sub
Private Sub alertControl1_AlertClick(ByVal sender As Object, ByVal e As AlertClickEventArgs) Handles alertControl1.AlertClick
Dim data As MailData = TryCast(e.Info.Tag, MailData)
OpenItem(data)
End Sub
#End Region
#Region "AlertPopupMenu"
Private updatePopupMenu As Boolean = False
Private Sub popupMenu1_BeforePopup(ByVal sender As Object, ByVal e As CancelEventArgs) Handles popupMenu1.BeforePopup
Dim args As AlertClickEventArgs = TryCast(popupMenu1.ItemLinks(0).Item.Tag, AlertClickEventArgs)
If args Is Nothing Then
Return
End If
Dim data As MailData = TryCast(args.Info.Tag, MailData)
updatePopupMenu = True
bcFlag.Checked = 0.Equals(data.Flag)
If 1.Equals(data.Read) Then
biRead.Caption = My.Resources.UnreadMark
biRead.ImageIndex = 2
Else
biRead.Caption = My.Resources.ReadMark
biRead.ImageIndex = 1
End If
If data.Priority = 0 Then
bcLow.Checked = True
End If
If data.Priority = 1 Then
bcMedium.Checked = True
End If
If data.Priority = 2 Then
bcHigh.Checked = True
End If
updatePopupMenu = False
End Sub
Private Sub biOpen_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles biOpen.ItemClick
Dim args As AlertClickEventArgs = TryCast(e.Item.Tag, AlertClickEventArgs)
OpenItem(TryCast(args.Info.Tag, MailData))
End Sub
Private Sub bcFlag_DownChanged(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles bcFlag.DownChanged
If updatePopupMenu Then
Return
End If
Dim args As AlertClickEventArgs = TryCast(e.Item.Tag, AlertClickEventArgs)
Dim data As MailData = TryCast(args.Info.Tag, MailData)
data.Flag = If(CType(e.Item, BarCheckItem).Checked, 0, 1)
args.AlertForm.Buttons("Flag").Down = data.Flag = 0
End Sub
Private Sub biRead_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs) Handles biRead.ItemClick
Dim args As AlertClickEventArgs = TryCast(e.Item.Tag, AlertClickEventArgs)
Dim data As MailData = TryCast(args.Info.Tag, MailData)
data.Read = If(data.Read = 1, 0, 1)
args.AlertForm.Buttons("Read").Down = data.Read = 1
End Sub
Private Sub biDelete_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs) Handles biDelete.ItemClick
Dim args As AlertClickEventArgs = TryCast(e.Item.Tag, AlertClickEventArgs)
DeleteItem(args, TryCast(args.Info.Tag, MailData))
End Sub
Private Sub bc_DownChanged(ByVal sender As Object, ByVal e As ItemClickEventArgs) Handles bcLow.DownChanged, bcMedium.DownChanged, bcHigh.DownChanged
If updatePopupMenu Then
Return
End If
Dim args As AlertClickEventArgs = TryCast(e.Item.Tag, AlertClickEventArgs)
Dim data As MailData = TryCast(args.Info.Tag, MailData)
Dim item As BarCheckItem = TryCast(e.Item, BarCheckItem)
If Not item.Checked Then
Return
End If
If bcLow.Checked Then
data.Priority = 0
End If
If bcMedium.Checked Then
data.Priority = 1
End If
If bcHigh.Checked Then
data.Priority = 2
End If
End Sub
Private Sub barManager1_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs) Handles barManager1.ItemClick
Dim args As AlertClickEventArgs = TryCast(e.Item.Tag, AlertClickEventArgs)
If args Is Nothing Then
Return
End If
Dim data As MailData = TryCast(args.Info.Tag, MailData)
args.AlertForm.OwnerForm.Activate()
End Sub
#End Region
Private Sub gridControl1_MouseDoubleClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles gridControl1.MouseDoubleClick
Dim hi As GridHitInfo = gridView1.CalcHitInfo(New Point(e.X, e.Y))
If hi.InRow AndAlso gridView1.FocusedRowHandle > -1 Then
mTimer.ShowAlert(New MailData(gridView1.GetDataRow(gridView1.FocusedRowHandle)))
End If
End Sub
Private Sub alertControl1_BeforeFormShow(ByVal sender As Object, ByVal e As AlertFormEventArgs) Handles alertControl1.BeforeFormShow
'((MailData)e.AlertForm.Info.Tag).Form.Activate();
End Sub
Protected Overrides Sub OnStyleChanged()
MyBase.OnStyleChanged()
ColorHelper.UpdateColor(imageList1, gridControl1.LookAndFeel)
End Sub
End Class
End Namespace