从 ComboBox 获取 DayOfWeek
我试图找到一种使用 DayOfWeek.Monday
的方法,但通过在表单上选择它来实现。
因此,如果用户从下拉组合框中选择“星期二”,那么以编程方式它将是DayOfWeek.Tuesday
。
这是当前的代码:
Do Until dtpEndMonth.DayOfWeek = DayOfWeek.Friday
我想说的是:
Do Until dtpEndMonth.DayOfWeek = DayOfweek.Me.Controls("ComboBox1").Value
有什么想法吗?
I'm trying to find a way of using DayOfWeek.Monday
but by selecting it on a form.
So if the user selects Tuesday from a drop down combo box, then programmatically it will be DayOfWeek.Tuesday
.
This is the current code:
Do Until dtpEndMonth.DayOfWeek = DayOfWeek.Friday
I want to say something like:
Do Until dtpEndMonth.DayOfWeek = DayOfweek.Me.Controls("ComboBox1").Value
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这种静态方法可行,您可以将字符串直接解析为 DayOfWeek-Enum:
If this static approach is viable, you could parse the string directly to the DayOfWeek-Enum:
实现此目的的一种方法是执行以下操作:
然后,当您想要获取所选值时:
这种方法利用了让
ComboBox
具有 Display 和 Value 成员的能力(通过DataSource
属性),以便当用户选择一个人性化的显示值,它们实际上是在幕后选择一个“数据值”,这就是您的代码处理的内容。注意:我没有测试此代码,因此可能存在拼写错误。如果您需要任何澄清或更正,请告诉我。
One way to do this would be by doing something like this:
Then when you want to get the selected value:
This approach leverages the ability to have a
ComboBox
have both a Display and a Value Member (via theDataSource
property), so that when the user selects a human-friendly display value, they are actually selecting a "data value" under the covers, which is what your code deal with.Note: I didn't test this code, so there may be typos. If you need any clarifications or corrections, let me know.