Affichage des articles dont le libellé est datagridview tutorial. Afficher tous les articles
Affichage des articles dont le libellé est datagridview tutorial. Afficher tous les articles

VB.Net Add Row To Datagridview From Another Form

How To Insert Rows To DataGridView From Another Form In Visual Basic.Net 

insert rows to datagridview from another form using VB.net

In This VB.Net Tutorial  We Will See How To Add Rows To DataGridView From TextBoxes On A Different Form Using Visual Basic.Net Programming Language And Visual Studio Editor.

and in this example we will create 2 forms:
1 - form_1 with a datagridview and a Button
2 - form_2with 3 textboxes and a button

when we click in form_1 button "open a new window" the second form will show up , you need to fill up the textboxes and click the 'add' button

- To Learn More Watch The Video Tutorial Below. 


Project Source Code:

' Form DataGridView
Public Class FormGRID

    ' open a new form to add the data
    Private Sub ButtonOpen_Click(sender As Object, e As EventArgs) Handles ButtonOpen.Click

        Dim fdata As New FormDATA()
        fdata.Show()


    End Sub

End Class


' Form TextBoxes
Public Class FormDATA

    ' button add data
    Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click


        ' add a new row with our data to the datagridview
        FormGRID.DataGridView1.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox3.Text)


    End Sub

End Class
   

Note: make sure to set the datagridview to static (better if you watch th full video)
   
///////////////OUTPUT:

This Is The End Result




insert data to DataGridView from another form in vb



C# DataGridView Header

How To Customize Datagridview Header In C#

C# DataGridView Header


In This C# Tutorial  We Will See How To Change Datagridview Header Text Size, Text Color, Font Name, Background Color, Text Alignment, In 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 Form17 : Form
    {
        public Form17()
        {
            InitializeComponent();
        }

        private void Form17_Load(object sender, EventArgs e)
        {
            // populate datagridview from datatable
            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;

            /*
            dataGridView1.Columns[0].HeaderCell.Style.Font = new Font("Tahoma", 18, FontStyle.Bold);
            dataGridView1.Columns[1].HeaderCell.Style.Font = new Font("Tahoma", 22, FontStyle.Italic);
            dataGridView1.Columns[2].HeaderCell.Style.Font = new Font("Tahoma", 25, FontStyle.Strikeout);
            dataGridView1.Columns[3].HeaderCell.Style.Font = new Font("Tahoma", 28, FontStyle.Underline);
            */

            dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 25, FontStyle.Bold);

            /*
            dataGridView1.Columns[0].HeaderCell.Style.ForeColor = Color.Red;
            dataGridView1.Columns[1].HeaderCell.Style.ForeColor = Color.Green;
            dataGridView1.Columns[2].HeaderCell.Style.ForeColor = Color.Blue;
            dataGridView1.Columns[3].HeaderCell.Style.ForeColor = Color.Brown;
            */

            dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.Blue;



            /*
            dataGridView1.Columns[0].HeaderCell.Style.BackColor = Color.White;
            dataGridView1.Columns[1].HeaderCell.Style.BackColor = Color.Yellow;
            dataGridView1.Columns[2].HeaderCell.Style.BackColor = Color.AliceBlue;
            dataGridView1.Columns[3].HeaderCell.Style.BackColor = Color.Aqua;
            */
            dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Yellow;

            // center text

            dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.TopLeft;

            dataGridView1.EnableHeadersVisualStyles = false;
        }
    }
}

// OUTPUT :

c# datagridview header