السلام على من اتبع الهدى ورحمة الله وبركاته
إخواني الأعزاء أعضاء قسم السي شارب
هذا كود منسوخ من قسم الفيجوال بيسك دوت نت ( مسروق )
ولكن بعد تحويلة إلى كود بلغة السي شارب وذلك لما تحدثنا عنه في الموضوع التالي
public class Form1 : System.Windows.Forms.Form
{
public Form1()
{
base.New();
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing) {
if (!((components == null))) {
components.Dispose();
}
}
base.Dispose(disposing);
}
private System.ComponentModel.IContainer components;
internal System.Windows.Forms.DataGrid DataGrid2;
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.DataGrid2 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.DataGrid2)).BeginInit();
this.SuspendLayout();
this.DataGrid2.DataMember = "";
this.DataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.DataGrid2.Location = new System.Drawing.Point(8, 8);
this.DataGrid2.Name = "DataGrid2";
this.DataGrid2.Size = new System.Drawing.Size(352, 168);
this.DataGrid2.TabIndex = 0;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(376, 189);
this.Controls.Add(this.DataGrid2);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.DataGrid2)).EndInit();
this.ResumeLayout(false);
}
DataSet ds = new DataSet("ds");
DataTable tb = new DataTable("tb");
DataRow row;
DataColumn myDataColumn;
private void Form1_Load(object sender, System.EventArgs e)
{
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.Int32");
myDataColumn.ColumnName = "id";
myDataColumn.Caption = "ID";
tb.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.Boolean");
myDataColumn.ColumnName = "Admin";
myDataColumn.Caption = "Admin";
tb.Columns.Add(myDataColumn);
int i;
for (int i = 0; i <= 2; i++) {
row = tb.NewRow();
row("id") = i;
row("Admin") = true;
tb.Rows.Add(row);
}
this.ds.Tables.Add(tb);
this.DataGrid2.DataSource = ds;
this.DataGrid2.DataMember = "tb";
BindCalcuationDataGrid();
}
void BindCalcuationDataGrid()
{
this.DataGrid2.TableStyles.Clear();
DataGridTableStyle grdTableStyle1 = new DataGridTableStyle();
grdTableStyle1.MappingName = this.ds.Tables(0).TableName;
DataGridTextBoxColumn grdColStyle1 = new DataGridTextBoxColumn();
grdColStyle1.MappingName = "id";
grdColStyle1.HeaderText = "الرقم التسلسلي";
grdColStyle1.Width = 150;
grdColStyle1.Alignment = HorizontalAlignment.Center;
grdColStyle1.NullText = string.Empty;
DataGridBoolColumn grdColStyle2 = new DataGridBoolColumn();
grdColStyle2.MappingName = "admin";
grdColStyle2.HeaderText = " المستخدم ";
grdColStyle2.Width = 90;
grdColStyle2.Alignment = HorizontalAlignment.Center;
grdColStyle2.FalseValue = false;
grdColStyle2.TrueValue = true;
grdColStyle2.NullValue = false;
grdTableStyle1.GridColumnStyles.AddRange(new DataGridColumnStyle[]{grdColStyle1, grdColStyle2});
this.DataGrid2.TableStyles.Add(grdTableStyle1);
}
}