Mini Kabibi Habibi
Imports System.Collections
Imports System.ComponentModel
Imports DevExpress.XtraGrid
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.DXperience.Demos
Namespace DevExpress.XtraGrid.Demos
''' <summary>
''' Summary description for ConditionsItem.
''' </summary>
Partial Public Class ConditionsItem
Inherits System.Windows.Forms.UserControl
Public Sub New()
' This call is required by the Windows.Forms Form Designer.
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
InitializeComponent()
propertyGrid1.ShowDescription = False
propertyGrid1.ShowCategories = propertyGrid1.ShowDescription
propertyGrid1.ShowButtons = propertyGrid1.ShowCategories
Me.BackColor = Color.Transparent
InitConditions()
' TODO: Add any initialization after the InitForm call
End Sub
Private be1 As BaseEdit = Nothing
Private be2 As BaseEdit = Nothing
Private item As StyleFormatCondition = Nothing
Private init As Boolean = False
Public Event RefreshValues As EventHandler
Private Sub InitConditions()
For Each mode As FormatConditionEnum In System.Enum.GetValues(GetType(FormatConditionEnum))
If mode = FormatConditionEnum.Expression Then
Continue For
End If
icbCondition.Properties.Items.Add(New ImageComboBoxItem(EnumTitlesKeeper(Of FormatConditionEnum).GetTitle(mode), mode, -1))
Next mode
End Sub
Private Sub SetCheckEditStyle(ByVal be As BaseEdit, ByVal s As String)
Dim ce As CheckEdit = CType(be, CheckEdit)
ce.Properties.AllowGrayed = True
ce.Text = s
End Sub
Private Sub SetSpinStyle(ByVal be As BaseEdit, ByVal type As Type)
Dim se As SpinEdit = CType(be, SpinEdit)
If "System.Int16System.Int32System.Int64System.Byte".IndexOf(type.ToString()) > -1 Then
se.Properties.IsFloatValue = False
End If
End Sub
Private Sub CreateValues(ByVal type As Type)
If type.Equals(GetType(Boolean)) Then
be1 = New CheckEdit()
be2 = New CheckEdit()
SetCheckEditStyle(be1, String.Format("{0}1", My.Resources.Value))
SetCheckEditStyle(be2, String.Format("{0}2", My.Resources.Value))
lbVal2.Visible = False
lbVal1.Visible = lbVal2.Visible
ElseIf type.IsValueType Then
be1 = New SpinEdit()
be2 = New SpinEdit()
SetSpinStyle(be1, type)
SetSpinStyle(be2, type)
Else
be1 = New TextEdit()
be2 = New TextEdit()
End If
be2.Size = New Size(icbCondition.Width, icbCondition.Height)
be1.Size = be2.Size
If type.Equals(GetType(Boolean)) Then
be1.Location = lbVal1.Location
be2.Location = lbVal2.Location
Else
be1.Location = New Point(icbCondition.Location.X, lbVal1.Location.Y)
be2.Location = New Point(icbCondition.Location.X, lbVal2.Location.Y)
End If
AddHandler be1.Validated, AddressOf val1_Validate
AddHandler be2.Validated, AddressOf val2_Validate
be1.TabIndex = 2
be2.TabIndex = 3
Me.Controls.Add(be1)
Me.Controls.Add(be2)
End Sub
Public Sub InitItem(ByVal item As StyleFormatCondition)
Me.item = item
init = True
Dim IsNull As Boolean = item Is Nothing
If Not IsNull Then
If be1 Is Nothing Then
CreateValues(item.Column.ColumnType)
End If
ceRow.Checked = item.ApplyToRow
propertyGrid1.PropertyGrid.SelectedObject = item.Appearance
icbCondition.EditValue = item.Condition
be1.EditValue = item.Value1
be2.EditValue = item.Value2
End If
icbCondition.Enabled = Not IsNull
ceRow.Enabled = icbCondition.Enabled
If be1 IsNot Nothing Then
be2.Visible = Not IsNull
be1.Visible = be2.Visible
End If
If IsNull Then
propertyGrid1.PropertyGrid.SelectedObject = Nothing
End If
init = False
End Sub
Private Sub RaiseRefreshValues()
RaiseEvent RefreshValues(Me, EventArgs.Empty)
End Sub
Private Sub icbCondition_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles icbCondition.SelectedIndexChanged
If init OrElse item Is Nothing Then
Return
End If
item.Condition = CType(icbCondition.EditValue, FormatConditionEnum)
RaiseRefreshValues()
End Sub
Private Sub ceRow_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ceRow.CheckedChanged
If init OrElse item Is Nothing Then
Return
End If
item.ApplyToRow = ceRow.Checked
End Sub
Private Sub SetValue(ByVal value1 As Boolean, ByVal val As Object)
Try
If val IsNot Nothing Then
val = Convert.ChangeType(val, item.Column.ColumnType)
End If
If value1 Then
item.Value1 = val
Else
item.Value2 = val
End If
Catch
End Try
init = True
If value1 Then
be1.EditValue = item.Value1
Else
be2.EditValue = item.Value2
End If
init = False
RaiseRefreshValues()
End Sub
Private Sub val1_Validate(ByVal sender As Object, ByVal e As EventArgs)
If init OrElse item Is Nothing Then
Return
End If
SetValue(True, be1.EditValue)
End Sub
Private Sub val2_Validate(ByVal sender As Object, ByVal e As EventArgs)
If init OrElse item Is Nothing Then
Return
End If
SetValue(False, be2.EditValue)
End Sub
End Class
End Namespace