C# - How Import and Export Data From XML File

C# - How Import and Export Data From XML File

                                                                                                                                  

In This C# Tutorial We Will See How To Export The DataGridView Values To A XML File Using CSharp Programming Language .


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 Csharp_Datagridview_XML : Form
    {
        DataTable table = new DataTable("tbl");
        public Csharp_Datagridview_XML()
        {
            InitializeComponent();
        }

        private void Csharp_Datagridview_XML_Load(object sender, EventArgs e)
        {
         
            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("First Name", typeof(string));
            table.Columns.Add("Last Name", typeof(string));
            table.Columns.Add("Age", typeof(int));

            table.Rows.Add(1, "First A", "Last A", 10);
            table.Rows.Add(2, "First B", "Last B", 20);
            table.Rows.Add(3, "First C", "Last C", 30);
            table.Rows.Add(4, "First D", "Last D", 40);
            table.Rows.Add(5, "First E", "Last E", 50);
            table.Rows.Add(6, "First F", "Last F", 60);
            table.Rows.Add(7, "First G", "Last G", 70);
            table.Rows.Add(8, "First H", "Last H", 80);
            table.Rows.Add(9, "First I", "Last I", 90);

            dataGridView1.DataSource = table;
        }

        private void BTN_EXPORT_Click(object sender, EventArgs e)
        {
            table.WriteXml(@"C:\Users\samsng\Documents\Visual Studio 2013\Projects\WindowsFormsApplication1\WindowsFormsApplication1\XMLFile1.xml",XmlWriteMode.WriteSchema);
            MessageBox.Show("Data Exported");
        }

        private void BTN_IMPORT_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.ReadXml(@"C:\Users\samsng\Documents\Visual Studio 2013\Projects\WindowsFormsApplication1\WindowsFormsApplication1\XMLFile1.xml");
            dataGridView2.DataSource = dt;
            MessageBox.Show("Data Imported");
        }
    }
}

=> OutPut :

c# import and export to xml file
c# import and export to xml file



C# -How To Export dataGridView Data to txt file

C# -How To Export dataGridView Data to txt file

                                                                                                                                  

In This C# Tutorial We Will See How To Write The DataGridView Values In A Text File Using CSharp Programming Language .



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 WindowsFormsApplication1
{
    public partial class Datagridview_to_txt_file : Form
    {
        public Datagridview_to_txt_file()
        {
            InitializeComponent();
        }

        private void Datagridview_to_txt_file_Load(object sender, EventArgs e)
        {
            DataTable table = new DataTable();
            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("First Name",typeof(string));
            table.Columns.Add("Last Name",typeof(string));
            table.Columns.Add("Age",typeof(int));

            table.Rows.Add(1, "First A", "Last A", 10);
            table.Rows.Add(2, "First B", "Last B", 20);
            table.Rows.Add(3, "First C", "Last C", 30);
            table.Rows.Add(4, "First D", "Last D", 40);
            table.Rows.Add(5, "First E", "Last E", 50);
            table.Rows.Add(6, "First F", "Last F", 60);
            table.Rows.Add(7, "First G", "Last G", 70);
            table.Rows.Add(8, "First H", "Last H", 80);
            table.Rows.Add(9, "First I", "Last I", 90);

            dataGridView1.DataSource = table;
        }

        private void BTN_EXPORT_Click(object sender, EventArgs e)
        {
            TextWriter writer = new StreamWriter(@"C:\folder\Text.txt");
            for(int i = 0; i < dataGridView1.Rows.Count-1; i++)
            {
                for(int j = 0; j < dataGridView1.Columns.Count; j++)
                {
                    writer.Write("\t"+dataGridView1.Rows[i].Cells[j].Value.ToString()+"\t"+"|");
                }
                writer.WriteLine("");
                writer.WriteLine("-----------------------------------------------------");
            }
            writer.Close();
            MessageBox.Show("Data Exported");
        }
    }

}
=
> OutPut :

Export Datagridview Data To Text File In C#
Export Datagridview Data To Text File In C#



C# - How To Add ComboBox Button CheckBox Image to dataGridView

C# - Add ComboBox Button CheckBox Image to dataGridView

                                                                                                                              

In This C# Tutorial We will See How To :

-add Combobox To Datagridview,
-add CheckboxTo Datagridview,
-add Button To Datagridview,
-add Image To Datagridview,


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 Datagridview_Add_Button_CheckBox_Combobox_Image : Form
    {
        public Datagridview_Add_Button_CheckBox_Combobox_Image()
        {
            InitializeComponent();
        }

        private void Datagridview_Add_Button_CheckBox_Combobox_Image_Load(object sender, EventArgs e)
        {
            DataTable table = new DataTable();
            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("First Name", typeof(string));
            table.Columns.Add("Last Name", typeof(string));
            table.Columns.Add("Age", typeof(int));

            table.Rows.Add(1, "First A", "Last A", 10);
            table.Rows.Add(2, "First B", "Last B", 20);
            table.Rows.Add(3, "First C", "Last C", 30);
            table.Rows.Add(4, "First D", "Last D", 40);
            table.Rows.Add(5, "First E", "Last E", 50);
            table.Rows.Add(6, "First F", "Last F", 60);
            table.Rows.Add(7, "First G", "Last G", 70);
            table.Rows.Add(8, "First H", "Last H", 80);
            table.Rows.Add(9, "First I", "Last I", 90);

            dataGridView1.DataSource = table;

            DataGridViewComboBoxColumn dcombo = new DataGridViewComboBoxColumn();
            dcombo.HeaderText = "ComboBox";

            dcombo.Items.Add("A");
            dcombo.Items.Add("B");
            dcombo.Items.Add("C");
            dcombo.Items.Add("D");

            DataGridViewButtonColumn dbtn = new DataGridViewButtonColumn();
            dbtn.HeaderText = "Button";

            DataGridViewCheckBoxColumn dchek = new DataGridViewCheckBoxColumn();
            dchek.HeaderText = "CheckBox";

            DataGridViewImageColumn dimg = new DataGridViewImageColumn();
            dimg.Image = Properties.Resources.myico;
            dimg.HeaderText = "Image";
            dimg.ImageLayout = DataGridViewImageCellLayout.Stretch;

            dataGridView1.AllowUserToAddRows = false;

            dataGridView1.Columns.Add(dcombo);
            dataGridView1.Columns.Add(dbtn);
            dataGridView1.Columns.Add(dchek);
            dataGridView1.Columns.Add(dimg);
        }
    }
}

=> OutPut :

c# Add ComboBox Button CheckBox Image to dataGridView
Add ComboBox Button CheckBox Image to dataGridView




C# - How to Bind dataGridView with Datatable In C#

C# Tutorial - How To Load Datatable Into DataGridView Using C#

                                                                                                                         

In This C# Tutorial We Will See How To Populate a DataGridView From DataTable Using CSharp Programming Language And Visual Studio 2013 .


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 Bind_DataGridView_Using_DataTable : Form
    {
        public Bind_DataGridView_Using_DataTable()
        {
            InitializeComponent();
        }

        private void Bind_DataGridView_Using_DataTable_Load(object sender, EventArgs e)
        {
            DataTable table = new DataTable();

            // add columns to datatable
            table.Columns.Add("Id", typeof(int));
            table.Columns.Add("First Name", typeof(string));
            table.Columns.Add("Last Name", typeof(string));
            table.Columns.Add("Age", typeof(int));

            // add rows to datatable
            table.Rows.Add(1,"First A","Last A",10);
            table.Rows.Add(2, "First B", "Last B", 20);
            table.Rows.Add(3, "First C", "Last C", 30);
            table.Rows.Add(4, "First D", "Last D", 40);
            table.Rows.Add(5, "First E", "Last E", 50);
            table.Rows.Add(6, "First F", "Last F", 60);
            table.Rows.Add(7, "First G", "Last G", 70);
            table.Rows.Add(8, "First H", "Last H", 80);

            dataGridView1.DataSource = table;

        }
    }
}

OutPut : 

load datatable data to datagridview using c#
Load DataTable To DataGridView



C# - How To Use Regex ( Regular Expressions ) In C#

C# - How To Use Regular Expressions ( Regex ) In C#

                                                                                                            

In This C# Tutorial We Will See How To  Validate:
-email.
-url.
-phone number.
-birthday.
Using Regex In CSharp Programming Language.


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.Text.RegularExpressions;


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

        private void button1_Click(object sender, EventArgs e)
        {
            //  mail@mail.com                        => ^([\w]+)@([\w]+)\.([\w]+)$
            //  http://www.google.com                => ^(http://www\.)([\w]+)\.([\w]+)$
            //  Phone Number like : 0011 XXX XXX XXX => ^(0011)(([ ][0-9]{3}){3})$
            //  Date XX/XX/XXXX                      => ^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$

            Regexp(@"^([\w]+)@([\w]+)\.([\w]+)$",textBox1, pictureBox1, lblemail, "Mail");

            Regexp(@"^(http://www\.)([\w]+)\.([\w]+)$", textBox2, pictureBox2, lblwebsite, "Web Site");
            Regexp(@"^(0011)(([ ][0-9]{3}){3})$", textBox3, pictureBox3, lblphone, "Phone Number");

            Regexp(@"^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$", textBox4, pictureBox4, lbldate, "Date");
        }

        public void Regexp(string re, TextBox tb, PictureBox pc, Label lbl, string s)
        {
            Regex regex = new Regex(re);

            if(regex.IsMatch(tb.Text))
            {
                pc.Image = Properties.Resources.valid;
                lbl.ForeColor = Color.Green;
                lbl.Text = s + " Valid";
            }
            else
            {
                pc.Image = Properties.Resources.invalid;
                lbl.ForeColor = Color.Red;
                lbl.Text = s + " InValid";
            }
        }
    }
}


=> OutPut :

c# regular expressions
C# Regex



      


c# - how to bind a combobox with fonts names

c# - how to bind a combobox with fonts name

                                                                                                                           

In This C# Tutorial We Will See How We Can Populate A ComboBox With Fonts Name And Set The Font Name To A Label Using CSharp Programming Language


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 ComboBox_Fonts_Names : Form
    {
        public ComboBox_Fonts_Names()
        {
            InitializeComponent();
        }

        private void ComboBox_Fonts_Names_Load(object sender, EventArgs e)
        {
            foreach(FontFamily font in FontFamily.Families)
            {
                comboBox1.Items.Add(font.Name.ToString());
            }
        }

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                label1.Font = new Font(comboBox1.Text, label1.Font.Size);
            }
            catch { }
        }
    }
}

=> OutPut :


C# ComboBox With Fonts Names
Populate A ComboBox With Fonts Names In C#



c# - How to clear the text of all textBoxes in the form or in The groupBox

c# - How to clear the text of all textBoxes in the form or in The groupBox

                                                                                        

In This C# Tutorial We Will See How You Can Remove The Text From All TextBoxes In The Form Or In The GroupBox Using CSharp Programming Language..


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 Clear_TextBoxes : Form
    {
        public Clear_TextBoxes()
        {
            InitializeComponent();
        }

        private void BTN_FORM_Click(object sender, EventArgs e)
        {
            foreach(Control c in Controls)
            {
                if(c is TextBox)
                {
                    c.Text = "";
                }
            }
        }

        private void BTN_GRBX_Click(object sender, EventArgs e)
        {
            foreach (Control c in groupBox1.Controls)
            {
                if (c is TextBox)
                {
                    c.Text = "";
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            BTN_FORM.PerformClick();
            BTN_GRBX.PerformClick();
        }
    }

}
=> OutPut :

Clear All TextBoxes In C#
Clear All TextBoxes In C#



C# - How To Create Login Form In C# With Access Database [with source code]

C# - How To Create Login Form In C# With Access Database [with source code]

C# - How To Create Login Form In C# With Access Database [with source code]

                                                                                                                                         

In This C# Tutorial We Will See How To Make A Login Form Using CSharp Programming Language And Access Database.



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.Windows.Forms;
using System.Data.OleDb;
 
namespace LoginPrj
{
    public partial class TestForm : Form
    {
        OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Documents\DataBase1.accdb");
        OleDbDataAdapter da;
        DataTable dt = new DataTable();
        public TestForm()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            da = new OleDbDataAdapter("select * from MyTab where Email='"+textBox1.Text+"' and Password='"+textBox2.Text+"'",cn);
            da.Fill(dt);
            if (dt.Rows.Count <= 0)
            {
                if(panel1.Height == 0)
                {
                    label1.Text = "Email Or Passwor are Invalide Please try again";
                    timer1.Start();
                }
                else if (panel1.Height == 100)
                {
                    timer2.Start();
                    label1.Text = "";
                }
            }
            else if (dt.Rows.Count > 0)
            {
                if (panel1.Height == 0)
                {
                    label1.Text = "Login Succsufully";
                    timer1.Start();
                }
                else if (panel1.Height == 100)
                {
                    timer2.Start();
                    label1.Text = "";
                }
            }
 
            dt.Clear();
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            if(panel1.Height != 100)
            {
                panel1.Height +=5;
                if(panel1.Height == 100)
                {
                    timer1.Stop();
                }
            }
        }
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (panel1.Height != 0)
            {
                panel1.Height -= 5;
                if (panel1.Height == 0)
                {
                    timer2.Stop();
                }
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            timer2.Start();
        }
    }
}

////////////////////////////////END
Other Login Form Post:
Create Login Form In C# With MySQL Database