遍历结构体中的项,添加每一项的值到ComboBox下拉项中
'cmbReportTaskState是要加载项的ComboBox With cmbReportTaskState '必须实例化一个新的结构体 Dim TaskStateType As New TaskStateType With .Items .Clear() '遍历任务状态结构体,加载每一项的值到下拉框中 For Each fieldInfo As FieldInfo In TaskStateType.GetType().GetFields() .Add(fieldInfo.GetValue(TaskStateType)) Next End With 'Items .DropDownStyle = ComboBoxStyle.DropDownList .SelectedIndex = .FindString(String.Empty) End With 'cmbReportTaskState ''' <summary> ''' 任务状态类别 ''' </summary> ''' <remarks></remarks> Public Structure TaskStateType Public Const Finished As String = "已完成" Public Const Unfinished As String = "未完成" Public Const Canceled As String = "已取消" Public Const Started As String = "已启动" Public Const NotStarted As String = "未启动" End Structure 'TaskStateType