473,396 Members | 1,895 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,396 software developers and data experts.

DataGrid Style

Hi all. Help! What am I doing wrong? My datagrid works fine, the
columns are created and the data is filled. However, I just cannot
resize the column widths to what I want them to be. I created a
TableStyle but it is ignored. :-(

I am using this code:
Dim DS As New DataSet
Dim MyTable As New DataTable
Dim Col0 As New DataColumn
Dim Col1 As New DataColumn
Dim Col2 As New DataColumn

DS.Tables.Add(0)
DS.Tables(0).Columns.Add(Col0)
DS.Tables(0).Columns(0).ColumnName = "Checked"
DS.Tables(0).Columns.Add(Col1)
DS.Tables(0).Columns(1).ColumnName = "Path"
DS.Tables(0).Columns.Add(Col2)
DS.Tables(0).Columns(2).ColumnName = "Node"
Dim newRow As DataRow

newRow = DS.Tables(0).NewRow
newRow.Item("Checked") = False
newRow.Item("Path") = datSplit(0)
newRow.Item("Node") = NodeName

DS.Tables(0).Rows.Add(ErrRow)

myDataGrid.DataSource = DS
myDataGrid.SetDataBinding(DS, DS.Tables(0).ToString)
--

Daniel
MCSE, MCP+I, MCP in Windows 2000/NT

--------------------------------------
remove the 2nd madrid from my mail address to contact me.
Nov 21 '05 #1
3 1416
Hi,

I dont see any code where you added a tablestyle to your grid.

Here is an example.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim ds As New DataSet

Dim daCustomers As OleDbDataAdapter

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn += "Data Source = C:\Northwind.mdb;"

conn = New OleDbConnection(strConn)

daCustomers = New OleDbDataAdapter("Select * from Customers", conn)

daCustomers.Fill(ds, "Customers")

SetupGrid()

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

End Sub

Private Sub SetupGrid()

Dim ts As New DataGridTableStyle

ts.MappingName = "Customers"

Dim colName As New DataGridTextBoxColumn

With colName

..MappingName = "ContactName"

..HeaderText = "Name"

..Width = 150

End With
Dim colID As New DataGridTextBoxColumn

With colID

..MappingName = "CustomerID"

..HeaderText = "ID"

..Width = 80

End With

Dim colRegion As New DataGridTextBoxColumn

With colRegion

..MappingName = "Region"

..HeaderText = "Region"

..Width = 80

..NullText = ""

End With

ts.GridColumnStyles.Add(colID)

ts.GridColumnStyles.Add(colName)

ts.GridColumnStyles.Add(colRegion)

DataGrid1.TableStyles.Add(ts)

ts = Nothing

colRegion = Nothing

colName = Nothing

colID = Nothing

End Sub

Ken
--------------------------
"Daniel" <da****@madridmadridsoleado.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi all. Help! What am I doing wrong? My datagrid works fine, the
columns are created and the data is filled. However, I just cannot
resize the column widths to what I want them to be. I created a
TableStyle but it is ignored. :-(

I am using this code:
Dim DS As New DataSet
Dim MyTable As New DataTable
Dim Col0 As New DataColumn
Dim Col1 As New DataColumn
Dim Col2 As New DataColumn

DS.Tables.Add(0)
DS.Tables(0).Columns.Add(Col0)
DS.Tables(0).Columns(0).ColumnName = "Checked"
DS.Tables(0).Columns.Add(Col1)
DS.Tables(0).Columns(1).ColumnName = "Path"
DS.Tables(0).Columns.Add(Col2)
DS.Tables(0).Columns(2).ColumnName = "Node"
Dim newRow As DataRow

newRow = DS.Tables(0).NewRow
newRow.Item("Checked") = False
newRow.Item("Path") = datSplit(0)
newRow.Item("Node") = NodeName

DS.Tables(0).Rows.Add(ErrRow)

myDataGrid.DataSource = DS
myDataGrid.SetDataBinding(DS, DS.Tables(0).ToString)
--

Daniel
MCSE, MCP+I, MCP in Windows 2000/NT

--------------------------------------
remove the 2nd madrid from my mail address to contact me.
Nov 21 '05 #2
Ken Tucker [MVP] wrote:
Hi,

I dont see any code where you added a tablestyle to your grid.

Here is an example.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim ds As New DataSet

Dim daCustomers As OleDbDataAdapter

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn += "Data Source = C:\Northwind.mdb;"

conn = New OleDbConnection(strConn)

daCustomers = New OleDbDataAdapter("Select * from Customers", conn)

daCustomers.Fill(ds, "Customers")

SetupGrid()

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

End Sub

Private Sub SetupGrid()

Dim ts As New DataGridTableStyle

ts.MappingName = "Customers"

Dim colName As New DataGridTextBoxColumn

With colName

..MappingName = "ContactName"

..HeaderText = "Name"

..Width = 150

End With
Dim colID As New DataGridTextBoxColumn

With colID

..MappingName = "CustomerID"

..HeaderText = "ID"

..Width = 80

End With

Dim colRegion As New DataGridTextBoxColumn

With colRegion

..MappingName = "Region"

..HeaderText = "Region"

..Width = 80

..NullText = ""

End With

ts.GridColumnStyles.Add(colID)

ts.GridColumnStyles.Add(colName)

ts.GridColumnStyles.Add(colRegion)

DataGrid1.TableStyles.Add(ts)

ts = Nothing

colRegion = Nothing

colName = Nothing

colID = Nothing

End Sub

Ken
--------------------------
"Daniel" <da****@madridmadridsoleado.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi all. Help! What am I doing wrong? My datagrid works fine, the
columns are created and the data is filled. However, I just cannot
resize the column widths to what I want them to be. I created a
TableStyle but it is ignored. :-(

I am using this code:
Dim DS As New DataSet
Dim MyTable As New DataTable
Dim Col0 As New DataColumn
Dim Col1 As New DataColumn
Dim Col2 As New DataColumn

DS.Tables.Add(0)
DS.Tables(0).Columns.Add(Col0)
DS.Tables(0).Columns(0).ColumnName = "Checked"
DS.Tables(0).Columns.Add(Col1)
DS.Tables(0).Columns(1).ColumnName = "Path"
DS.Tables(0).Columns.Add(Col2)
DS.Tables(0).Columns(2).ColumnName = "Node"
Dim newRow As DataRow

newRow = DS.Tables(0).NewRow
newRow.Item("Checked") = False
newRow.Item("Path") = datSplit(0)
newRow.Item("Node") = NodeName

DS.Tables(0).Rows.Add(ErrRow)

myDataGrid.DataSource = DS
myDataGrid.SetDataBinding(DS, DS.Tables(0).ToString)

Thanks for this however i get the error "The data grid table styles
collection already contains a table style with the same mapping name"

This is because I have already created the tablestyle via the properties
of the datagrid in the IDE. My problem is that the style I created is
ignored! Any ideas?

--

Daniel
MCSE, MCP+I, MCP in Windows 2000/NT

--------------------------------------
remove the 2nd madrid from my mail address to contact me.
Nov 21 '05 #3
Daniel wrote:
Ken Tucker [MVP] wrote:
Hi,

I dont see any code where you added a tablestyle to your
grid.

Here is an example.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim ds As New DataSet

Dim daCustomers As OleDbDataAdapter

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn += "Data Source = C:\Northwind.mdb;"

conn = New OleDbConnection(strConn)

daCustomers = New OleDbDataAdapter("Select * from Customers", conn)

daCustomers.Fill(ds, "Customers")

SetupGrid()

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

End Sub

Private Sub SetupGrid()

Dim ts As New DataGridTableStyle

ts.MappingName = "Customers"

Dim colName As New DataGridTextBoxColumn

With colName

..MappingName = "ContactName"

..HeaderText = "Name"

..Width = 150

End With
Dim colID As New DataGridTextBoxColumn

With colID

..MappingName = "CustomerID"

..HeaderText = "ID"

..Width = 80

End With

Dim colRegion As New DataGridTextBoxColumn

With colRegion

..MappingName = "Region"

..HeaderText = "Region"

..Width = 80

..NullText = ""

End With

ts.GridColumnStyles.Add(colID)

ts.GridColumnStyles.Add(colName)

ts.GridColumnStyles.Add(colRegion)

DataGrid1.TableStyles.Add(ts)

ts = Nothing

colRegion = Nothing

colName = Nothing

colID = Nothing

End Sub

Ken
--------------------------
"Daniel" <da****@madridmadridsoleado.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi all. Help! What am I doing wrong? My datagrid works fine, the
columns are created and the data is filled. However, I just cannot
resize the column widths to what I want them to be. I created a
TableStyle but it is ignored. :-(

I am using this code:
Dim DS As New DataSet
Dim MyTable As New DataTable
Dim Col0 As New DataColumn
Dim Col1 As New DataColumn
Dim Col2 As New DataColumn

DS.Tables.Add(0)
DS.Tables(0).Columns.Add(Col0)
DS.Tables(0).Columns(0).ColumnName = "Checked"
DS.Tables(0).Columns.Add(Col1)
DS.Tables(0).Columns(1).ColumnName = "Path"
DS.Tables(0).Columns.Add(Col2)
DS.Tables(0).Columns(2).ColumnName = "Node"
Dim newRow As DataRow

newRow = DS.Tables(0).NewRow
newRow.Item("Checked") = False
newRow.Item("Path") = datSplit(0)
newRow.Item("Node") = NodeName

DS.Tables(0).Rows.Add(ErrRow)

myDataGrid.DataSource = DS
myDataGrid.SetDataBinding(DS, DS.Tables(0).ToString)

Thanks for this however i get the error "The data grid table styles
collection already contains a table style with the same mapping name"

This is because I have already created the tablestyle via the properties
of the datagrid in the IDE. My problem is that the style I created is
ignored! Any ideas?

It is OK, I worked it out. I binned the tablestyle that i made in the
IDE and just created it via code and it works. 1 line i missed though
was "MyTS.MappingName = mYTable.GetType().Name" where MyTS is the New
TableStyle.

--

Daniel
MCSE, MCP+I, MCP in Windows 2000/NT

--------------------------------------
remove the 2nd madrid from my mail address to contact me.
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
2
by: Marty McDonald | last post by:
When setting certain datagrid properties with the IDE (as in the property window), they don't seem to take effect. For instance, Font Name. So I have to set these via code-behind at the cell...
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
2
by: ltt19 | last post by:
Hi. I have a DataGrid control that has one HyperLinkColumn, and this page has a "default.css" loaded, so, the link Style of the DataGrid is the same of the css document... but I want to change it,...
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
2
by: cj | last post by:
I was looking over some of my 2003 code today (see below) that loads a foxpro table via oledb connection. I used a sub "autosizecolumns" I found on the web but I never quite understood why they...
6
by: slinky | last post by:
I found the following code to transfer datagrid data to an Excel file. Is this written in C#?... I'm a vb.netter. I'm just not sure where to place the code to experiment on it. Should I place it in...
1
by: Brock | last post by:
First note that I am using Framework 1.1. I have an .aspx page that is displaying a list of employees, but only the Employee Number, First Name, Last Name, and Title. It is working great. I...
1
by: Brock | last post by:
Thanks in advance... (you can see a screenshot of what my form looks like currently at http://www.juggernautical.com/DataGrid.jpg - the Datalist is super-imposed in 'design view' but the DataGrid...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.