Results 1 to 3 of 3

Thread: DataGrid Problem [URGENT]

  1. #1

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    DataGrid Problem [URGENT]

    Hello everybody,

    I have a DataTable and I bind the DataTable with DataGrid. It shows all the columns with equal width. In these columns, I have a description field which contains large data. I need to increase width of this particular column of DataGrid.

    Thanks.

  2. #2
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Re: DataGrid Problem [URGENT]

    you can have a table mappings here, like this sample:
    VB Code:
    1. private void Form1_Load(object sender, System.EventArgs e)
    2.         {
    3.             //conn is a connection from sql
    4.             //DataAdapter da
    5.             DataTable dt = new DataTable();
    6.             da.SelectCommand=new SqlCommand("select * from Products",conn);
    7.             da.Fill(dt);
    8.             this.dataGrid1.DataSource=dt;
    9.  
    10.             DataGridTableStyle dgt = new DataGridTableStyle();
    11.             dgt.MappingName=dt.TableName;
    12.  
    13.             DataGridTextBoxColumn dgtbc = new DataGridTextBoxColumn();
    14.             dgtbc.MappingName=dt.Columns[0].ColumnName;
    15.             dgtbc.HeaderText = "ID"; // Product ID
    16.             dgtbc.Width=50;
    17.            
    18.             DataGridTextBoxColumn dgtbc1 = new DataGridTextBoxColumn();
    19.             dgtbc1.MappingName=dt.Columns[1].ColumnName;
    20.             dgtbc1.HeaderText = "Description"; // description
    21.             dgtbc1.Width=200;
    22.            
    23.             dgt.GridColumnStyles.AddRange(new DataGridTextBoxColumn[] {dgtbc,dgtbc1});
    24.  
    25.             this.dataGrid1.TableStyles.Add(dgt);
    26.            
    27.         }
    you can also add some other columns depends on your stuff to view.

  3. #3
    Member
    Join Date
    Mar 2005
    Posts
    43

    Re: DataGrid Problem [URGENT]

    Go to the property builder of you datagrid (in design mode), next select format. Then you select your column and there you can fill in the width.

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