Click here to Skip to main content
15,897,704 members
Articles / Programming Languages / C#
Article

How to Make an Arabic Column in DataGridView

Rate me:
Please Sign up or sign in to vote.
2.75/5 (3 votes)
20 Sep 2008CPOL 34K   17   4
Arabic Column in DataGridView

Introduction

Some people make applications that have an Arabic Interface. We cannot name any column in Arabic in any RDBMS, however DataGridView can solve this problem by giving an Arabic name to your column when you display your data.

Using the Code

There are two ways to make an Arabic column in DataGridView.

The first way is very easy and can be done by changing the header text of DataGridView as follows:

C#
dataGridView1.Columns[0].HeaderText = "???????";

dataGridView1.Columns[1].HeaderText = "?????";

dataGridView1.Columns[2].HeaderText = "?????";

The second way is that DataGridViewTextBoxColumn is used to host cells that enable displaying and editing of text strings.

Steps

  1. Create an instance from DataGridViewTextBoxColumn class

  2. Add cells you created to be hosted in dataGridView1:

    C#
    dataGridView1.Columns.AddRange(new DataGridViewTextBoxColumn[] {
            idDataGridViewTextBoxColumn,
            nameDataGridViewTextBoxColumn,
            ageDataGridViewTextBoxColumn});
  3. Ok, after you add cells to dataGridView, you want to make a link between the cell which you write Arabic text on and the column:

    C#
    idDataGridViewTextBoxColumn.DataPropertyName = "id";
    idDataGridViewTextBoxColumn.HeaderText = "?";

Example

C#
DataGridViewTextBoxColumn idDataGridViewTextBoxColumn;
DataGridViewTextBoxColumn nameDataGridViewTextBoxColumn;
DataGridViewTextBoxColumn ageDataGridViewTextBoxColumn;

private void Form1_Load(object sender, EventArgs e)
{
    idDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
    nameDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
    ageDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();

    dataGridView1.Columns.AddRange(new DataGridViewTextBoxColumn[] {
        idDataGridViewTextBoxColumn,
            nameDataGridViewTextBoxColumn,
            ageDataGridViewTextBoxColumn});

        using (SqlConnection sqlCon = new SqlConnection(
            @"Data Source=.\SQLEXPRESS;AttachDbFilename=" +
            "C:\Documents and Settings\Administrator\My Documents\AhmedRabie.mdf;" +
            "Integrated Security=True;Connect Timeout=30;User Instance=True"))
        {
            SqlCommand cmd = sqlCon.CreateCommand();
            cmd.CommandText = "Select * from StudentInfo";
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = cmd;
            DataSet dset = new DataSet();
            adapter.Fill(dset);

            idDataGridViewTextBoxColumn.DataPropertyName = "id";
            idDataGridViewTextBoxColumn.HeaderText = "?";
            idDataGridViewTextBoxColumn.Name = "idDataGridViewTextBoxColumn";
            // 
            // nameDataGridViewTextBoxColumn
            // 
            nameDataGridViewTextBoxColumn.DataPropertyName = "name";
            nameDataGridViewTextBoxColumn.HeaderText = "?????";
            nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn";
            // 
            // ageDataGridViewTextBoxColumn
            // 
            ageDataGridViewTextBoxColumn.DataPropertyName = "age";
            ageDataGridViewTextBoxColumn.HeaderText = "?????";
            ageDataGridViewTextBoxColumn.Name = "ageDataGridViewTextBoxColumn";

            dataGridView1.DataSource = dset.Tables[0];
        }
}

History

  • 20th September, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer ITeShare
Egypt Egypt
I am interested in Software architecture, Requirements Engineering and coding. I am MCP ,SCJP,MCTs,MCPD, Brainbench.

http://ahmedbohoty.blogspot.com/

Comments and Discussions

 
GeneralDatagridview Pin
Saad_ang4-May-11 4:43
Saad_ang4-May-11 4:43 
GeneralMy vote of 1 Pin
Mohm'ed Melhem3-Aug-09 2:20
professionalMohm'ed Melhem3-Aug-09 2:20 
Questionand how can we do following Pin
sairfan121-Nov-08 21:56
sairfan121-Nov-08 21:56 
Lets take an example. we have a DataGridView with 2 columns, both columns are combobox columns and are databound. First column contains Company and second column Products. At run time in first column when i select company second column must filled with its products, focus should ramain at first column until i press enter. Moreover when ever second column is refereshed its first value should be selected by default or how can i set it combobox2.SelectedIndex = 0 property at run time while having focus in first column.

It should work like this, when i select in first column Company Nestle 2nd column should fill automatically with Nestle's products. like Milk, Kit Kat, Nesveta and so on, and first product Milk should be selected by default, please note that it is required while first Column Company is being edited.
Generalالف شكر يا حمد Pin
EgyptionLion3-Oct-08 18:45
EgyptionLion3-Oct-08 18:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.