C# Populate Combobox From Text File

How To Fill A ComboBox With Items From .TXT File Using C#

Populate Combobox From Text File Using C#

In This C# Tutorial  We Will See How To Import And Display Data From a Text File to a Combobox Using datatable + File.ReadAllLines() and For Loop In Csharp Programming Language And Visual Studio Editor.



Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace Csharp_Tutorials
{
    public partial class TEXT_FILE_TO_COMBO : Form
    {
        public TEXT_FILE_TO_COMBO()
        {
            InitializeComponent();
        }

        private void TEXT_FILE_TO_COMBO_Load(object sender, EventArgs e)
        {

            string[] lines = File.ReadAllLines(@"C:\Users\1BestCsharp\Desktop\table2.txt");
            string[] data = new string[lines.Length];

            for(int i = 0; i < lines.Length; i++)
            {
                data[i] = i + 1 + " > " + lines[i];
            }

            comboBox1.DataSource = data;
        }
    }
}

      
///////////////OUTPUT:

Fill Combobox From TXT File Using C#




C# Add Action To All Buttons

How To Add Action To All Buttons In The Form Using C#

add action to all buttons in c#



This C# tutorial will provide a guide on creating a click event and applying it to all buttons within a form in CSharp programming language, utilizing the Visual Studio IDE. By following the steps outlined in this tutorial, you will gain valuable insight into effectively managing event handling in your C# projects.




Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class AddEventToAllButtons : Form
    {
        public AddEventToAllButtons()
        {
            InitializeComponent();
        }

        private void AddEventToAllButtons_Load(object sender, EventArgs e)
        {

            foreach (Control c in Controls)
            {
                if (c is Button)
                {
                    c.Click += new System.EventHandler(btn_Click);
                }
            }

        }

        private void btn_Click(object sender, EventArgs e)
        {
            Button btn = (Button) sender;
            label1.Text = btn.Text;

        }
        
    }
}                                       

////// OUTPUT : 

add event click to all buttons using c#





C# DateTimePicker

How To Use A DateTimePicker Control In C#

Using DateTimePicker In C#

In This C# Tutorial We Will See How To Use DateTimePicker Control To Do The Following Things:
- customize the date format.
- set a default date.
- set a minimum date.
- set a maximum date.
- add days.
- add months.
- add years.
- get the full date.
- get day value.
- get month value.
- get year value.
Using Csharp Programming Language And Visual Studio Editor.


Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Csharp_Tutorials
{
    public partial class Using_DateTimePicker : Form
    {
        public Using_DateTimePicker()
        {
            InitializeComponent();
        }

        private void Using_DateTimePicker_Load(object sender, EventArgs e)
        {
            // custom date format
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "MM-dd-yyyy";
            
            // set date
            dateTimePicker1.Value = new DateTime(2000, 7, 10);

            // min date
            dateTimePicker1.MinDate = new DateTime(1900, 1, 1);

            // max date
            dateTimePicker1.MaxDate = new DateTime(2500, 1, 1);

        }

        private void buttonADD_Click(object sender, EventArgs e)
        {

            // add days to the dateTimePicker date
            // dateTimePicker1.Value = dateTimePicker1.Value.AddDays(4);

            // add months to the dateTimePicker date
            // dateTimePicker1.Value = dateTimePicker1.Value.AddMonths(4);

            // add years to the dateTimePicker date
            // error from the max date

             dateTimePicker1.Value = dateTimePicker1.Value.AddYears(4);
        }

        private void buttonGET_Click(object sender, EventArgs e)
        {
            // get full date
            textBox1.Text = dateTimePicker1.Value.ToString();

            // get day value
            textBox1.Text = dateTimePicker1.Value.Day.ToString();

            // get month value
            textBox1.Text = dateTimePicker1.Value.Month.ToString();

            // get year value
            textBox1.Text = dateTimePicker1.Value.Year.ToString();
        }
    }
}

      




VB.Net Add Node To TreeView

How To Insert A New Node To TreeView Using Visual Basic .Net

;Add Node To TreeView Using Visual Basic .Net

In this VB.NET Tutorial we will see How To Add a New Node Or a Root From TextBox  Using Visual Basic.Net Programming Language And Visual  Studio Editor.




Project Source Code:


Public Class Add_Node_To_TreeView

    Private Sub ButtonADD_Click(sender As Object, e As EventArgs) Handles ButtonADD.Click

        Dim node As New TreeNode(TextBox1.Text)

        'add child node
        'TreeView1.SelectedNode.Nodes.Add(node)

        'add root
        TreeView1.Nodes.Add(TextBox1.Text)

    End Sub
End Class


OutPut:

Insert New Node To TreeView Using VB.Net