DataGrid question

H

HS1

Hello



I use a DataGrid to present data of a table ("Jobs") through a DataSet (ds)
using a DataAdapter (da)



I use the query for DataAdapter (da):



SELECT JobID, Job_Description, Architects, ClientID From Jobs



Then I use the code below to fill data into the DataGrid1

DataGrid1.DataSource = ds

DataGrid1.DataMember = "Jobs"

da.Fill(ds)

What I want is to present the JobID in the first column, the Job_Description
in the second column and so on. However, when I do the code as above, the
Datagrid shows column (fields) following the order: Architects, ClientID,
JobID and Job_Description

Could you please help to present the column order in a DataGrid.

Thank you very much for your help

SH1
 
C

Cor Ligthert

SH1, (when you close with your first name we can make more friendly
messages) :)

For that are the datagridtablestyles.

The samples on MSDN about this are in my opinion a little bit complex on
first sight therefore I made a sample with only 2 textboxcolumns and used is
a dataset.
You can make that as well from a dataview or whatever. Have a look at MSDN
for the almost endless possibilities from this.

\\\
DataGrid1.DataSource = ds.Tables("Persons")
Dim ts As New DataGridTableStyle
ts.MappingName = "Persons"
'The name of the datatable, this is case sensitive
Dim textCol As New DataGridTextBoxColumn
textCol.MappingName = "Name"
'the name of the used column, this is case sensitive
textCol.HeaderText = "First Name"
textCol.Width = 120
ts.GridColumnStyles.Add(textCol)
textCol = New DataGridTextBoxColumn
textCol.MappingName = "Country"
textCol.HeaderText = "Living in"
textCol.Width = 50
ts.GridColumnStyles.Add(textCol)
DataGrid1.TableStyles.Add(ts)
///

http://msdn.microsoft.com/library/d...mWindowsFormsDataGridTableStyleClassTopic.asp

When this sample above is not clear as well please tell it than,

I hope this helps a little bit?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top