winforms

Binding a Dictionary to the DataGridView in C#?

纵饮孤独 提交于 2021-02-07 07:17:14
问题 I have a dictionary item as below Dictionary<string, List<StrikePrice>> where public class StrikePrice { public string Strike { get; private set; } public string Price { get; private set; } public StrikePrice(string strike, string price) { Strike = strike; Price = price; } } and I wish to assign this dictionary to the DataGridView this.dataGridViewTest.DataSource = listSmiles; I understand that a dictionary can't be assigned to the the DataSource as this doesn't derive from the IList

Binding a Dictionary to the DataGridView in C#?

回眸只為那壹抹淺笑 提交于 2021-02-07 07:14:42
问题 I have a dictionary item as below Dictionary<string, List<StrikePrice>> where public class StrikePrice { public string Strike { get; private set; } public string Price { get; private set; } public StrikePrice(string strike, string price) { Strike = strike; Price = price; } } and I wish to assign this dictionary to the DataGridView this.dataGridViewTest.DataSource = listSmiles; I understand that a dictionary can't be assigned to the the DataSource as this doesn't derive from the IList

WinForms window changes dimensions when it encounters an async call

不打扰是莪最后的温柔 提交于 2021-02-07 07:01:23
问题 I have a WinForms project which is several years old and has been retro-fitted with async event-handlers: private async void dgvNewOrders_CellClick(object sender, DataGridViewCellEventArgs e) Inside this method is an async call: var projectTemplate = await GetProjectTemplateFile(companyId, sourceLang, targetLang); When the program runs on a normal resolution screen, it runs as expected. However, when run on a high-DPI screen the window's dimensions - as well as those of all child controls -

Why does my icon not appear in the title bar?

∥☆過路亽.° 提交于 2021-02-07 06:44:05
问题 I have assigned an icon to my application from the Properties window in Solution Explorer in Visual Studio; the application's icon changed successfully but the title bar is still showing the default icon: I've rebuilt my application but it still displays the default icon. What am I doing wrong? 回答1: Because forms have a different icaon configuration than the application. Set the icon on the form, not ONLY on the application. 回答2: The form itself has an Icon property you need to set as well.

How to use System.ComponentModel.DataAnnotations in WPF or Winforms application

你。 提交于 2021-02-07 06:39:49
问题 is it possible to use System.ComponentModel.DataAnnotations and it's belong attribute(such as Required , Range ,...) in WPF or Winforms class? I want put my validation to attributs. thanks EDIT 1: I write this : public class Recipe { [Required] [CustomValidation(typeof(AWValidation), "ValidateId", ErrorMessage = "nima")] public int Name { get; set; } } private void Window_Loaded(object sender, RoutedEventArgs e) { var recipe = new Recipe(); recipe.Name = 3; var context = new ValidationContext

Adding the check boxes in the TREEVIEW in c#

大城市里の小女人 提交于 2021-02-07 04:54:09
问题 i want to add the check box to the child node of a certain parent node in the tree view in my application...How should i add it? 回答1: TreeView has a property with the name CheckBoxes , if set to true , it shows checkboxes for all child nodes. 回答2: The TreeView API only allows you to add/remove checkboxes for EVERY node. If that's what you want, then the answer is easy - use the TreeView's CheckBoxes property. If you want a checkbox for a particular node in the tree only, then it gets tricky.

Using lambda function in a foreach over controls [duplicate]

*爱你&永不变心* 提交于 2021-02-07 04:37:14
问题 This question already has answers here : Foreach Control in form, how can I do something to all the TextBoxes in my Form? (14 answers) Closed 3 years ago . I would like to translate this: foreach(Control c in Controls) { if(c is TextBox) { // ... } } Into: foreach(Control c => (c is TextBox) in Controls) { // ... } How can it be done using the lambda function specifically? 回答1: Reference Linq: using System.Linq; And use this: foreach (var control in Controls.Cast<Control>().Where(c => c is

How do I detect insertion of USB devices category wise in C# winform?

梦想与她 提交于 2021-02-07 04:00:47
问题 USB thumb drives USB harddisks USB DVD writer USB Bluetooth devices USB headsets usb mouse USB keyboard USB webcams / cameras Just want to detect any sort of usb device using event handler... Would appreciate any help... WqlEventQuery q_creation = new WqlEventQuery(); private void Form2_Load(object sender, EventArgs e) { q_creation.EventClassName = "__InstanceCreationEvent"; q_creation.WithinInterval = new TimeSpan(0, 0, 2); //How often do you want to check it? 2Sec. q_creation.Condition = @

How do I detect insertion of USB devices category wise in C# winform?

倾然丶 夕夏残阳落幕 提交于 2021-02-07 03:59:02
问题 USB thumb drives USB harddisks USB DVD writer USB Bluetooth devices USB headsets usb mouse USB keyboard USB webcams / cameras Just want to detect any sort of usb device using event handler... Would appreciate any help... WqlEventQuery q_creation = new WqlEventQuery(); private void Form2_Load(object sender, EventArgs e) { q_creation.EventClassName = "__InstanceCreationEvent"; q_creation.WithinInterval = new TimeSpan(0, 0, 2); //How often do you want to check it? 2Sec. q_creation.Condition = @

Binding ObservableCollection to DataGridView

依然范特西╮ 提交于 2021-02-07 03:16:38
问题 I am binding an observable collection (FoodList) to a BindingSource in my WinForm. This BindingSource is used by a datagrid on the form. I had assumed that when I added a new item to the collection it would raise an event and a new row would show up in my grid. This does not happen though. namespace Foods { public class FoodList : ObservableCollection<Food> { } } private void frmFoods_Load(object sender, EventArgs e) { try { foodSource = new Source("Foods.xml"); foodBindingSource.DataSource =