473,480 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Highlight a column in a datagrid

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
1 1543
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4963
by: Gerg | last post by:
The datagrid has a tablestyle applied to it, and there are DataGridTextBoxColumn and each DataGridTextBoxColumn has an array of DataGridTextBox objects. Private Sub highlight(ByVal str As...
2
1703
by: Ben Bloom | last post by:
I've got a datagrid with a column named "Type". If cells in this column contain "Error" I would like to highlight them (say - turn the text red, or the background red.) How do I do this? Is...
0
819
by: reiks | last post by:
I want to highlight a row of my datagrid (web control) without using the any select bound column or link buton. Also the cursor should remain in the samehighlighted row for editing. How can I...
4
2165
by: Chris | last post by:
I've searched, reviewed, and attempted dozens of code ideas on the subject. I can't seem to get something that seems so simple to work. To highlight a row in a datagrid based on another value in...
6
3412
by: LU | last post by:
A)I build a datagrid based on a calendar date selection. B)When user clicks a button column on the datagrid I want to highlight this row. I use the code below to highlight the row. ***** CODE...
2
1603
by: Geraldine Hobley | last post by:
Hello I have a datagrid, called MyDataGrid and I wish to put the focus on a particular cell in order that the user to highlight the fact that the user needs to enter a value in this cell, e.g. I put...
1
993
by: John | last post by:
In Windows form, is that possible to highlight a column in datagrid? Thanks.
2
2062
by: Sridhar | last post by:
Hi, I have a datagrid which contains 3 columns. Two of them are Bound Column types and the third one is Button Column. When I click on one of the rows in that Button Column, I would like to...
3
1776
by: kurtzky | last post by:
I'm working in VS 2003. I have a datagrid and its AllowSort property is set to true. The columns of my grid are Inv No, Inv Desc and Apply To. I added a function that will Search for an...
0
7044
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7084
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6739
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6929
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
181
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.