I found out that my combobox Drawitem event doesn't fired sometimes, even when I change text in that combobox.
I have 2 questions:
When will combobox Drawitem event be triggered?
How can I trigger combobox drawitem in code?
by the way, this is my combobox drawitem event and that combobox related Func...
#Region "red tax "
Private Sub cboTaxRitsu_DrawItem(sender As Object, e As DrawItemEventArgs) Handles cboTaxRitsu.DrawItem
Try
Dim index As Integer = cboTaxRitsu.GetIndex(sender)
Dim i As Object = cboTaxRitsu(index).Items(e.Index)
'Dim i As Object = cboTaxRitsu(index).Text
If i IsNot Nothing Then
'draw disabled cbb
If (e.State = (DrawItemState.Disabled Or DrawItemState.NoAccelerator Or DrawItemState.NoFocusRect Or DrawItemState.ComboBoxEdit)) Then
cboTaxRitsu(index).DropDownStyle = ComboBoxStyle.DropDownList
If e.Index = colorTax Then
e.Graphics.DrawString(i, e.Font, New SolidBrush(Color.Red), e.Bounds)
Else
e.Graphics.DrawString(i, e.Font, New SolidBrush(Color.Black), e.Bounds)
End If
'e.DrawFocusRectangle()
Else
If e.Index = colorTax Then
e.Graphics.DrawString(i, e.Font, New SolidBrush(Color.Red), e.Bounds)
Else
e.Graphics.DrawString(i, e.Font, New SolidBrush(Color.Black), e.Bounds)
End If
End If
End If
Catch ex As Exception
End Try
End Sub
Private Sub cboTaxRitsu_TextChanged(sender As Object, e As EventArgs) Handles cboTaxRitsu.TextChanged
Dim index As Integer = cboTaxRitsu.GetIndex(sender)
If cboTaxRitsu(index).Text = cboTaxRitsu(index).Items(colorTax).ToString Then
cboTaxRitsu(index).ForeColor = Color.Red
Else
cboTaxRitsu(index).ForeColor = Color.Black
End If
End Sub
Private Sub cboTaxRitsu_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboTaxRitsu.SelectedIndexChanged
Dim index As Integer = cboTaxRitsu.GetIndex(sender)
If cboTaxRitsu(index).Text = cboTaxRitsu(index).Items(colorTax).ToString Then
cboTaxRitsu(index).ForeColor = Color.Red
Else
cboTaxRitsu(index).ForeColor = Color.Black
End If
If Check_Kingaku(txtKingaku(Index).Text) Then '金額適性チェック
Set_GT_Kingaku(index)
Calc_G_Gokei()
End If
End Sub
Private Sub cboTaxRitsu_EnabledChanged(sender As Object, e As EventArgs) Handles cboTaxRitsu.EnabledChanged
Dim index As Integer = cboTaxRitsu.GetIndex(sender)
If cboTaxRitsu(index).Enabled Then
Debug.Print(index & " : " & cboTaxRitsu(index).Text)
If cboTaxRitsu(index).Text = "" Then
cboTaxRitsu(index).SelectedIndex = defaultTax
End If
Else
cboTaxRitsu(index).Text = cboTaxRitsu(index).SelectedText
End If
cboTaxRitsu(index).DropDownStyle = ComboBoxStyle.DropDownList
End Sub
#End Region
When ever I use this combobox, I clear all combobox in form
sForm.cboTaxRitsu(RecNo).DropDownStyle = ComboBoxStyle.DropDown
sForm.cboTaxRitsu(RecNo).Text = ""
Then set
.sngTaxRitsu = sngTaxritsuHolder
If .sngTaxRitsu = 0 Then
sForm.cboTaxRitsu(Index).Text = ""
Else
sForm.cboTaxRitsu(Index).Text = VB6.Format(.sngTaxRitsu, "0.0#")
End If
items will be added when the form is loaded and will not be changed when the form in use
sForm.cboTaxRitsu(i).Items.Clear()
If cuTaxRitsu1 <> -1 Then
sForm.cboTaxRitsu(i).Items.Add(cuTaxRitsu1)
End If
If cuTaxRitsu2 <> -1 Then
sForm.cboTaxRitsu(i).Items.Add(cuTaxRitsu2)
End If
If cuTaxRitsu3 <> -1 Then
sForm.cboTaxRitsu(i).Items.Add(cuTaxRitsu3)
End If
Thank you for reading!