Results 1 to 7 of 7

Thread: Property shown in help file doesn't exist?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    37

    Property shown in help file doesn't exist?

    I finally read my Excel file, load it into a datagrid, define how the datagrid looks, adjust column names, width, etc. etc., the works.

    But now I want the second column to be the first column, so;

    ColumnA ColumnB ColumnC ColumnD

    becomes

    ColumnB ColumnA ColumnC ColumnD

    When looking around the help files I get the following;

    Using auto-generated columns is a quick and easy way to display information in the grid. Because these columns are automatically generated at run time and displayed in the order in which they occur in the data source, you do not have flexibility in how these columns are laid out.... ....You should explicitly define columns when you want to control which columns to display and in what order.

    And you can do that with the autogeneratecolumn property of a datagrid.

    Auto-Generated Columns
    If the DataGrid control's AutoGenerateColumn property is set to true, the control will generate and display a bound column for each bindable column in the data source.

    In other words, set datagridX.AutoGenerateColumn = false and define them yourself. Problem being, I don't see such a property anywhere.....

    Do any of you? What am I missing here?

    And any suggestions on how to switch the positions of my two columns?

  2. #2

  3. #3
    Junior Member gotcha_crazy's Avatar
    Join Date
    Jun 2004
    Location
    Cambridge, UK
    Posts
    31
    I agree with Marty, I thought this was a .net property.

    Just trying a solution for switching.

    [EDIT]

    Ok, column switch can be done like this:


    Private Sub Form_Load()

    'Add a column at position 2
    DataGrid.Columns.Add (2)

    'Set this to have the same Datafield as column 1
    DataGrid.Columns(2).DataField = DataGrid.Columns(0).DataField

    'Set the caption to the same
    DataGrid.Columns(2).Caption = DataGrid.Columns(0).Caption

    'Drop column 1
    DataGrid.Columns(0).Visible = False

    'Rebind the grid
    DataGrid.ReBind

    End Sub


    Any probs, let me know

    We're nearly here!!!!!!
    Last edited by gotcha_crazy; Jun 24th, 2004 at 03:39 AM.

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    37
    I'm using visual basic .net yeah, so as far as I can see it should work for me, but it doesn't. Also datagrid.columns doesn't exist in .net.

    As to my problem I 'solved' it by changing my select from statement, reading the columns I want in the order I want. Which I don't really like because I wanted to select * just in case some column name doesn't exist.

    I'm not changing my code again to test this out, but after some more thinking and using code I found searching on this forum I think the following should reorder columns aswell.

    Dim tsTableStyle As New DataGridTableStyle
    Dim tcTextCol As DataGridTextBoxColumn
    Dim i As Integer

    DataGrid1.TableStyles.Clear()
    tsTableStyle.MappingName = DS_MS.Tables(0).TableName()

    For i = 0 To DS_MS.Tables(0).Columns.Count() - 1
    tcTextCol = New DataGridTextBoxColumn
    tcTextCol.MappingName = "name of column you want"
    tcTextCol.Alignment = HorizontalAlignment.Center
    tsTableStyle.GridColumnStyles.Add(tcTextCol)
    Next
    DataGrid1.TableStyles.Add(tsTableStyle)

  5. #5

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    37
    Uhm, just wondering as my use of visual basic .net was one of availability and I don't know much about all the differences between versions etc.

    Any questions at all I have I should post in .net (as I'm using .net)? Because I thought 'developing database' was the correct thread, but I do have found many examples don't work when I try them out in .net.

    Just wondering.

  7. #7

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