Click here to Skip to main content
Click here to Skip to main content

How to Make an Arabic Column in DataGridView

, 20 Sep 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
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:

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:

    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:

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

Example

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)

Share

About the Author

Ahmed R El Bohoty
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 PinmemberSaad_ang4-May-11 5:43 
GeneralMy vote of 1 PinmemberMohm'ed Melhem3-Aug-09 3:20 
Questionand how can we do following Pinmembersairfan121-Nov-08 22:56 
Generalالف شكر يا حمد Pinmemberegyptionyouth3-Oct-08 19:45 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411023.1 | Last Updated 20 Sep 2008
Article Copyright 2008 by Ahmed R El Bohoty
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid