CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #4
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: DataGrid problems

    The following code is working:
    Code:
    //Initializing
    dataGridTableStyle1 = new DataGridTableStyle();
    dataGridTextBoxColumn1 = new DataGridTextBoxColumn();
    dataGridTextBoxColumn2 = new DataGridTextBoxColumn();
    dataGrid1.BeginInit();
     
    //Creating DataSource
    DataTable dt = new DataTable("MyTable");
    dt.Columns.Add(New DataColumn("X",typeof(string));
    dt.Columns.Add(New DataColumn("Y",typeof(string));
    dataGrid1.DataSource = dt;
     
    // dataGridTableStyle1
    
    dataGrid1.TableStyles.AddRange(new DataGridTableStyle[] {dataGridTableStyle1});
    dataGridTableStyle1.DataGrid = dataGrid1;
    dataGridTableStyle1.GridColumnStyles.AddRange(new DataGridColumnStyle[] {dataGridTextBoxColumn1,dataGridTextBoxColumn2});
    dataGridTableStyle1.MappingName = "MyTable"; // This is the name of the table you are binding to.
     
    // dataGridTextBoxColumn1
    dataGridTextBoxColumn1.HeaderText = "XXX"; // This is the text that is written in the Column Header. Leave empty to show the name of the column.
    dataGridTextBoxColumn1.MappingName = "X"; // This is the name of the column.
    dataGridTextBoxColumn1.ReadOnly = true;
    dataGridTextBoxColumn1.Width = 75;
     
     
    // dataGridTextBoxColumn2
    dataGridTextBoxColumn2.HeaderText = "YYY"; 
    dataGridTextBoxColumn2.MappingName = "Y"; // This is the name of the column.
    dataGridTextBoxColumn2.ReadOnly = false;
    dataGridTextBoxColumn2.Width = 75;
     
    dataGrid1.EndInit();
    
    The column with header YYY should be editable. The column with header XXX will be read-only.
    Last edited by jhammer; October 9th, 2005 at 02:29 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured