|
-
Jun 23rd, 2004, 08:28 PM
#1
Thread Starter
Member
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?
-
Jun 24th, 2004, 01:04 AM
#2
I believe that's a .Net property. Is that what you are using?
-
Jun 24th, 2004, 03:22 AM
#3
Junior Member
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.
-
Jun 24th, 2004, 03:58 PM
#4
Thread Starter
Member
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)
-
Jun 24th, 2004, 04:09 PM
#5
Originally posted by cphoenixc
I'm using visual basic .net yeah...
OK then, I've moved your thread to the correct forum.
-
Jun 24th, 2004, 04:16 PM
#6
Thread Starter
Member
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.
-
Jun 24th, 2004, 04:21 PM
#7
Database Development was OK, I didn't notice where I was moving it from but maybe you'll get some help here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|