473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Resizing Datagrid columns nightmare

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
6 1335
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
* "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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gord | last post by:
Hello, Anybody know how to detect when a user drags between columns in a MSHFlexGrid when resizing column width? (Short of setting up a timer event that continuously monitors column width.)...
0
by: kvinsi | last post by:
I would like grid stops with "right" resizing when mouse (spliter) come very close to the next column (sa same as it happens when you size "on the left"
3
by: bismarkjoe | last post by:
Hello, I am trying to set the widths on the columns of a DataGrid component, and I'm not sure if I'm doing it correctly. My code is below: //load some inital data table = db.GetDataTable(...
4
by: Dave | last post by:
Hello All, I am having a nightmare trying to add a new row to my Datagrid. When I use the code below I get the error: 'Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount. Can...
1
by: John Paul. A (MCP ID# 3015176) | last post by:
Hi, In a ASP.NET page I have a DataGrid Control populated with some data. I want to resize the DataGrid columns using mouse. That is, when I move the cursor to the edge of a column, the cursor...
0
by: Paul | last post by:
Hi I have a datagrid with two different hyperlink columns. The columns open up a new window as the target is set to _blank for both. The windows are different sizes (one large, one small) and I...
4
by: skOOb33 | last post by:
I successfully autosized the columns and rows on my Datagrid, and am now facing another issue. Having the sorting ability by clicking the column headers is key, but when I do that, it resizes all...
2
by: Nina | last post by:
Hi there, I've tried everything that I know to prevent usre resizing datagrid columns, but nothing works. Following are the code that I used. Please tell me what's wrong with them. Thank you....
2
by: lord.zoltar | last post by:
I have a DataGridView that has potentially several hundred rows (possibly a thousand or two). I'd like for each row to have the proper height to accomadate the text in the row. I tried setting the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...
0
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.