Edit DataGridView columns

T

thomasp

Will someone tell me why with the following code:

1. The user can not resize the columns
2. The DTG column is not formatted as "dd-MMM-yy HH:mm:ss"
3. The user can modify the data in all columns

Is it because on the line: .AutoGenerateColumns = True ?
If so can I somehow over ride this after the code has generated the columns?

Thanks,

Thomas


Private Sub frmViewTables_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim strTitle As String = ""

myConnection = New OleDbConnection(strConn)

Select Case intImportType
Case Is = 1
strSQL = "Select * from LCMR"
strTitle = "LCMR DataTable"
strTable = "LCMR"
Case Is = 2
strSQL = "Select * from Q36"
strTitle = "Q36 DataTable"
strTable = "Q36"
Case Is = 3
strSQL = "Select * from UTAMS"
strTitle = "UTAMS DataTable"
strTable = "UTAMS"
Case Else
Exit Sub
End Select

Me.Text = strTitle

myConnection.Open()

da = New OleDb.OleDbDataAdapter(strSQL, myConnection)
cmdBuilder = New OleDbCommandBuilder(da)
da.FillSchema(ds, SchemaType.Source, strTable)
da.Fill(ds, strTable)
tblDataTable = ds.Tables(0)
With DataGridView1
.AllowUserToResizeRows = True
.AutoGenerateColumns = True
.DataSource = ds
.DataMember = strTable '"table"
.AllowUserToResizeColumns = True
.AutoSizeColumnsMode =
DataGridViewAutoSizeColumnsMode.DisplayedCells
.Columns("DTG").DefaultCellStyle.Format = "dd-MMM-yy HH:mm:ss"
.ColumnHeadersHeightSizeMode =
DataGridViewColumnHeadersHeightSizeMode.EnableResizing
.Columns("ID").ReadOnly = True
.Columns("DTG").ReadOnly = True
.Columns("POO").ReadOnly = True
.Columns("POO_Alt").ReadOnly = True
.Columns("POI").ReadOnly = True
.Columns("POI_Alt").ReadOnly = True
.Columns("Distance").ReadOnly = True
.Columns("Direction").ReadOnly = True
If intImportType = 2 Then
.Columns("Db").ReadOnly = True
.Columns("Velocity").ReadOnly = True
End If
End With

End Sub
 
T

thomasp

I was able to get the DTG formated as wanted, but have still not been able
to set the desired columns to readonly. Any help will be appreciated.

Thomas
 

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