ComboBox中Tag的使用,转换为Enum类型

 

private ClientMessageObject CreateNewMessage() {
   ClientMessageObject cmsg = new ClientMessageObject();
   RtfFilter filter = new RtfFilter();
   String contentText = filter.ConvertFromDocument(this.rtbContent.Document);
   int[] receiverUserIds = (int[])this.txtRecipient.Tag;
   String recipientName = this.txtRecipient.Text;
   String strReceiverUserIds = WfMessageContent.IntArrayToString(",", receiverUserIds);
   cmsg.Content = this.GetContent(contentText, recipientName, strReceiverUserIds);

//Tag的引用,转换为Enum类型:
   cmsg.Priority =(WfPriority)((ComboBoxItem)this.ucePriority.SelectedItem).Tag;
   cmsg.SentDateTime = DateTime.Now;
   cmsg.Sid = new Guid();
   cmsg.SourceType = MessageSourceTypes.User;
   cmsg.Subject = this.txtSubject.Text;
   cmsg.UnRead = false;
   IUser user = (IUser)this._recipient;
   if (user != null) {
    cmsg.UserId = user.UserID;
    cmsg.UserName = recipientName;
   } else {
    if (this._clientMessage != null) {
     cmsg.UserId = this._clientMessage.UserId;
     cmsg.UserName = this._clientMessage.UserName;
    }
   }
   cmsg.WorkOrderNum = "";

   return cmsg;
  }

 

 

private void InitializeUcePriority() {
   Type type = typeof(WfPriority);
   foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.Static | BindingFlags.Public)) {
    ComboBoxItem item = new ComboBoxItem();
    item.Content = this.GetWfPriorityDisplayTextFromResx(fieldInfo.Name);

//定义Tag
    item.Tag = (Int32)(WfPriority)fieldInfo.GetValue(type);
    this.ucePriority.Items.Add(item);
   }
   this.ucePriority.SelectedIndex = 2;
  }

 

#region Localization
  private string GetWfPriorityDisplayTextFromResx(String priority) {
   switch (priority.ToLower()) {
    case "highest":
     return BoxPropertyCollectionResx.highest;
    case "high":
     return BoxPropertyCollectionResx.high;
    case "normal":
     return BoxPropertyCollectionResx.normal;
    case "low":
     return BoxPropertyCollectionResx.low;
    case "lowest":
     return BoxPropertyCollectionResx.lowest;
    default:
     return string.Empty;
   }
  }
  #endregion

转载于:https://www.cnblogs.com/stragon/archive/2010/01/07/1640884.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值