Results 1 to 4 of 4

Thread: DataGrid control problem

  1. #1

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60

    DataGrid control problem

    Hi all,

    I am trying to create a form that will allow a user to enter values against items for each day of the week.

    I am looking at the Datagrid control to do this, using a DataTable as it's source.

    My problems are that I cannot work out how I can customize the DataGrid's colmn widths. The Item width needs to be large, but the values small. Is this possible?

    Secondly, how do I prevent the end-user from adding records - I do not want them too, but there is always a new record line at the bottom of the data grid.

    In fact, if anyone can suggest a control better suited for doing this I'd be most interested.

    Many Thanks.

  2. #2
    Junior Member ost's Avatar
    Join Date
    Jan 2004
    Posts
    19
    if you want to go with the datagrid you can use a "datagridTableStyle" like this..


    Code:
    Dim tableStyle As New DataGridTableStyle
    tableStyle.MappingName = "TableName"
    
    Dim column As New DataGridTextBoxColumn
    column.MappingName = "Productname"
    column.HeaderText = "Productname"
    column.Width = 200
    column.ReadOnly() = True
    tableStyle.GridColumnStyles.Add(column)
    
    Dim AnswerCol As New DataGridTextBoxColumn
    AnswerCol.MappingName = "Yes"
    AnswerCol.HeaderText = "Yes"
    AnswerCol.Width = 30
    AnswerCol.AllowNull = False
    tableStyle.GridColumnStyles.Add(AnswerCol)
    
    AnswerCol = New DataGridTextBoxColumn
    AnswerCol.MappingName = "No"
    AnswerCol.HeaderText = "No"
    AnswerCol.Width = 30
    AnswerCol.AllowNull = False
    tableStyle.GridColumnStyles.Add(AnswerCol)
    
    AnswerCol = New DataGridTextBoxColumn
    AnswerCol.MappingName = "Error"
    AnswerCol.HeaderText = "Error"
    AnswerCol.Width = 30
    AnswerCol.AllowNull = False
    tableStyle.GridColumnStyles.Add(AnswerCol)
    
    Me.MyDataGrid.TableStyles.Add(tableStyle)
    to turn off the extra line at the bottom just make the datagrid ReadOnly. Then you can set in the "datagridTableStyle" column.ReadOnly() = False

    An example of how to customize a datagrid is found at:

    Custom Datagrid

  3. #3

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60

    Thumbs up

    Thank you, that looks like just what I'm after.
    Will try it tomorrow.

  4. #4

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60
    Well I have got a lot further now, however I'm still unable to get rid of the auto 'new row' line at the bottom of the grid (this being fixed data in which the user must not add a new row).

    Making the datagrid readonly - prevents this new row line from appearing, but also overrides all the colmns so they are all read-only as well (despite .Readonly = False on the columns) - thus the user cannot change any data either, which is not what i want!

    I will also be needed a total columen and row for this which will no doubt prove tricky to impossible!

    Any further advice much appreciated, Thanks.

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