By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,265 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,265 IT Pros & Developers. It's quick & easy.

Highlight a column in a datagrid

P: n/a
I have a datagrid with a column that I want to change the background
color so it stands out. Basically there is VB a procedure that imports
a text file directly into the datagrid. The last column in the
datagrid, results, I want highlighted and I just can't figure it
out.... Here is the code I have so far:

Sub OLE_SQL()
Dim strSelect As String = "SELECT * FROM sampleResult.txt"
Dim strConString As String
Dim strDataSource As String

Dim strConString1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source="
Dim strConString2 As String = ";Extended
Properties='text;FMT=Delimited'"
strConString = strConString1 & strDataSource & strConString2

Dim objConnect As New OleDb.OleDbConnection(strConString)
Dim objCommand As New OleDb.OleDbCommand(strSelect, objConnect)

Dim myDataSet As New DataSet

Dim objAdapter As New OleDb.OleDbDataAdapter(objCommand)

objConnect.Open()
objAdapter.Fill(myDataSet)
objConnect.Close()

myDataSet.Tables(0).Columns(0).ColumnName = "Sample ID"
myDataSet.Tables(0).Columns(1).ColumnName = "Date Collected"
myDataSet.Tables(0).Columns(2).ColumnName = "Time Collected"
myDataSet.Tables(0).Columns(3).ColumnName = "T1"
myDataSet.Tables(0).Columns(4).ColumnName = "T2"
myDataSet.Tables(0).Columns(5).ColumnName = "Person Sampling"
myDataSet.Tables(0).Columns(6).ColumnName = "Sample ID"
myDataSet.Tables(0).Columns(7).ColumnName = "Result"
Dim dbTable1 As New DataTable
dbTable1 = myDataSet.Tables(0)
DataGrid1.DataSource = dbTable1
DataGrid1.DataBind()

'Highlights the Result Column (7)
DataGrid1.Columns(7).ItemStyle.BackColor = System.Drawing.Color.Yellow

End Sub

But when it runs an error is thrown on
DATAGRID1.COLUMNS(7).ITEMSTYLE....

Index was out of range. Must be non-negative and less than the size of
the collection. Parameter name: index

Any help on this would be very welcome.
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

Datagrid.Select(rownum)
http://msdn.microsoft.com/library/de...electtopic.asp
Ken
--------------------
"PuckInLA" <sh*****@ensafe.com> wrote in message
news:43**************************@posting.google.c om...
I have a datagrid with a column that I want to change the background
color so it stands out. Basically there is VB a procedure that imports
a text file directly into the datagrid. The last column in the
datagrid, results, I want highlighted and I just can't figure it
out.... Here is the code I have so far:

Sub OLE_SQL()
Dim strSelect As String = "SELECT * FROM sampleResult.txt"
Dim strConString As String
Dim strDataSource As String

Dim strConString1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source="
Dim strConString2 As String = ";Extended
Properties='text;FMT=Delimited'"
strConString = strConString1 & strDataSource & strConString2

Dim objConnect As New OleDb.OleDbConnection(strConString)
Dim objCommand As New OleDb.OleDbCommand(strSelect, objConnect)

Dim myDataSet As New DataSet

Dim objAdapter As New OleDb.OleDbDataAdapter(objCommand)

objConnect.Open()
objAdapter.Fill(myDataSet)
objConnect.Close()

myDataSet.Tables(0).Columns(0).ColumnName = "Sample ID"
myDataSet.Tables(0).Columns(1).ColumnName = "Date Collected"
myDataSet.Tables(0).Columns(2).ColumnName = "Time Collected"
myDataSet.Tables(0).Columns(3).ColumnName = "T1"
myDataSet.Tables(0).Columns(4).ColumnName = "T2"
myDataSet.Tables(0).Columns(5).ColumnName = "Person Sampling"
myDataSet.Tables(0).Columns(6).ColumnName = "Sample ID"
myDataSet.Tables(0).Columns(7).ColumnName = "Result"
Dim dbTable1 As New DataTable
dbTable1 = myDataSet.Tables(0)
DataGrid1.DataSource = dbTable1
DataGrid1.DataBind()

'Highlights the Result Column (7)
DataGrid1.Columns(7).ItemStyle.BackColor = System.Drawing.Color.Yellow

End Sub

But when it runs an error is thrown on
DATAGRID1.COLUMNS(7).ITEMSTYLE....

Index was out of range. Must be non-negative and less than the size of
the collection. Parameter name: index

Any help on this would be very welcome.
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.