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

Resizing Datagrid columns nightmare

P: n/a
Hey,

I have been working on this for a while now and I keep getting the same
error.

here is my code:

------- start code ---------
Dim strSQL = "Select tagid,itemid,description,status, transtype, (select
max(datetime) from transactions where tagid = inventory.tagid) as statusdate
from inventory"

Dim connect as new SqlConnection([Sql Connection Stringgoes here])
connect.open()

Dim ds as New DataSet
Dim da as New DataAdapter(strSQL, connect)
da.Fill(ds, "Inventory")
da.FillSchema(ds.Tables("Inventory"), SchemaType.Source)

DataGrid1.DataSource = ds.Tables("Inventory")

DataGrid1.TableStyles.Clear()
Dim objTblStyle as DataGridTableStyles = new DataGridTableStyles()
objTblStyle.MappingName = "Inventory"

Dim objGridColStyles as GridColumnStylesCollection
objGridColStyles = objTblStyle.GridColumnStyles

DataGrid1.TableStyles.Add(objTblStyle)

DataGrid1.TableStyles("Inventory").AlternatingBack Color = Color.LightGray

DataGrid1.TableStyles("Inventory").GridColumnStyle s(0).Width = 150

------- end code --------

If I comment the last line of the code the code executes and the alternating
backcolors work.

with the last line uncommented, i get an Index Out of Range Error

and if i replace the (0) with ("tagid") or the name of another column I get
an Item not set to an instance of object error.

any help would be greatly appreciated.

Thanks,

Jim


Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
BB
Jim,

I didn't play with the code, but am I missing where you
actually create each grid column? Looks to me from the
error message that your objGridColStyles is empty.
-----Original Message-----
Hey,

I have been working on this for a while now and I keep getting the sameerror.

here is my code:

------- start code ---------
Dim strSQL = "Select tagid,itemid,description,status, transtype, (selectmax(datetime) from transactions where tagid = inventory.tagid) as statusdatefrom inventory"

Dim connect as new SqlConnection([Sql Connection Stringgoes here])connect.open()

Dim ds as New DataSet
Dim da as New DataAdapter(strSQL, connect)
da.Fill(ds, "Inventory")
da.FillSchema(ds.Tables("Inventory"), SchemaType.Source)

DataGrid1.DataSource = ds.Tables("Inventory")

DataGrid1.TableStyles.Clear()
Dim objTblStyle as DataGridTableStyles = new DataGridTableStyles()objTblStyle.MappingName = "Inventory"

Dim objGridColStyles as GridColumnStylesCollection
objGridColStyles = objTblStyle.GridColumnStyles

DataGrid1.TableStyles.Add(objTblStyle)

DataGrid1.TableStyles("Inventory").AlternatingBac kColor = Color.LightGray
DataGrid1.TableStyles("Inventory").GridColumnStyl es (0).Width = 150
------- end code --------

If I comment the last line of the code the code executes and the alternatingbackcolors work.

with the last line uncommented, i get an Index Out of Range Error
and if i replace the (0) with ("tagid") or the name of another column I getan Item not set to an instance of object error.

any help would be greatly appreciated.

Thanks,

Jim


.

Nov 20 '05 #2

P: n/a
* "Jim Mirra" <jm******@comcast.net> scripsit:
I have been working on this for a while now and I keep getting the same
error.


Multipost topics /are/ indeed a nightmare.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
Hi,

I changed your code as follows, and that works on my machine.
You may have a try and let me know the result.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strSQL = "select CustomerId,(select CompanyName from customers
where ContactName = 'Maria Anders') as des from customers"
Dim connectstring As String = Me.SqlConnection1.ConnectionString
Dim connect As New SqlClient.SqlConnection(connectstring)
connect.Open()
Dim ds As New DataSet
Dim da As New SqlClient.SqlDataAdapter(strSQL, connect)
da.Fill(ds, "Customers")
da.FillSchema(ds.Tables("Customers"), SchemaType.Source)
DataGrid1.DataSource = ds.Tables("Customers")
DataGrid1.TableStyles.Clear()
Dim objTblStyle As DataGridTableStyle = New DataGridTableStyle
objTblStyle.MappingName = "Customers"
Dim objGridColStyles As GridColumnStylesCollection
objGridColStyles = objTblStyle.GridColumnStyles
DataGrid1.TableStyles.Add(objTblStyle)
DataGrid1.TableStyles("Customers").AlternatingBack Color =
Color.LightGray
DataGrid1.TableStyles("Customers").GridColumnStyle s(0).Width = 150
End Sub

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #4

P: n/a
My apologies this is my first time using newsgroups and wasn't sure if my
post went through as it did not show up in my newsreader.

Sorry for any harm I may have caused you.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:br***********@ID-208219.news.uni-berlin.de...
* "Jim Mirra" <jm******@comcast.net> scripsit:
I have been working on this for a while now and I keep getting the same
error.


Multipost topics /are/ indeed a nightmare.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #5

P: n/a
No it still gives the same error. Do you think it has to do with the fact
that my query comes from multiple tables and not from one table as in your
example?

Jim

"Peter Huang" <v-******@online.microsoft.com> wrote in message
news:eG**************@cpmsftngxa07.phx.gbl...
Hi,

I changed your code as follows, and that works on my machine.
You may have a try and let me know the result.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strSQL = "select CustomerId,(select CompanyName from customers
where ContactName = 'Maria Anders') as des from customers"
Dim connectstring As String = Me.SqlConnection1.ConnectionString
Dim connect As New SqlClient.SqlConnection(connectstring)
connect.Open()
Dim ds As New DataSet
Dim da As New SqlClient.SqlDataAdapter(strSQL, connect)
da.Fill(ds, "Customers")
da.FillSchema(ds.Tables("Customers"), SchemaType.Source)
DataGrid1.DataSource = ds.Tables("Customers")
DataGrid1.TableStyles.Clear()
Dim objTblStyle As DataGridTableStyle = New DataGridTableStyle
objTblStyle.MappingName = "Customers"
Dim objGridColStyles As GridColumnStylesCollection
objGridColStyles = objTblStyle.GridColumnStyles
DataGrid1.TableStyles.Add(objTblStyle)
DataGrid1.TableStyles("Customers").AlternatingBack Color =
Color.LightGray
DataGrid1.TableStyles("Customers").GridColumnStyle s(0).Width = 150
End Sub

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #6

P: n/a
Hi Jim,

I also test with the SQL statement below.
Dim strSQL = "select CustomerId,(select count(OrderID) from Orders where
CustomerID = 'ALFKI')as des from customers"
I still can not reproduce the problem.

To isolate the problem, I think you may try to simplify your sql statement.
e.g. select tagid from inventory
or you can try to use another database, e.g. northwind it will be shipped
with office ,VB98 or Microsoft SDK and it will be named NWIND.MDB.

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.