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 = "???????";
ataGridView1.Columns[1].HeaderText = "?????";
d
taGridView1.Columns[2].HeaderText = "?????";
d
a
The second way is that DataGridViewTextBoxColumn
is used to host cells that enable displaying and editing of textstring
s.
Steps
Create an instance from
DataGridViewTextBoxColumn
classAdd cells you created to be hosted in
dataGridView1
:Collapse
dataGridView1.Columns.AddRange(new DataGridViewTextBoxColumn[] {idDataGridViewTextBoxColumn,nameDataGridViewTextBoxColumn,ageDataGridViewTextBoxColumn});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:Collapse
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
0 التعليقات:
إرسال تعليق