C# Custom control – TextBox accepting only numbers, decimal numbers, signed numbers

| | | | |

The creation of custom control using Visual Studio involves the following steps:

  1. Start Visual Studio;
  2. Create new “Windows Control Library” project;
  3. In the created project delete “User Control” file;
  4. Go to “Project” > “Add User Control” and give it a name;

    2016/07/29 21:38

C# - How to add reference to project

| |

To add a reference to CSharp project do the following:

1) Open “Solution Explorer”;
2) Right click “References”;
3) Choose “Add Reference”.

On the Reference Manager Window go to: “Assemblies” -> “Framework”. In the list find the reference you need, select it and checkup the checkbox in front it. Then select “OK”.

2016/07/27 18:23

C# Textbox - enter only positive numbers on KeyPress event in Windows form application

| | |

To prevent users from entering incorrect data in Windows form application, set restriction to allow only specific characters to be entered in the text box.

This example uses KeyPress event to monitor the users input and to apply the restriction required.

2016/07/22 18:16

c# combobox set selected item by item's text

| | |

C# Combobox defined with name my_combobox

private System.Windows.Forms.ComboBox my_combobox;

Define string variable with the text of the combobox item that has to be selected. For example, if the combobox items have text values "item_a" "item_b" "item_c" ... and the item which text is "item_b" has to be selected

string select_this_item = "item_b";string item_text = "";  int i = 0;for (i = 0; i < my_combobox.Items.Count; i++) {    item_text = my_combobox.GetItemText(my_combobox.Items[i]);    if (item_text == select_this_item)    {       my_combobox.SelectedItem = (object)my_combobox.Items[i];       break;    }}

2016/05/04 23:10

c# passing data between forms

| |

In C# project with two forms

public partial class Form1

2016/05/04 20:43

c# combobox fill from database

| | |

To get only the unique /distinct/ data table records from any database connected to DataSet in C# project and to put them inside combobox.

Fill the table adapter with the records from database.

2016/05/04 20:26

c# Get selected item text from combobox

| | |

C# Combobox defined with name my_combobox

private System.Windows.Forms.ComboBox my_combobox;

Read the text of the selected combobox item and assign it to string variable, then show it in message box.

string selected_item_text = my_combobox.GetItemText(my_combobox.SelectedItem);MessageBox.Show(selected_item_text);

2016/04/28 19:48

DataGridView copy to clipboard

| |


To copy the content of DataGridView cells to clipboard using MouseClick function


2016/04/19 17:43