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

DataGrid has me tied up once again!


I was going along fine in my test to see how to manipulate the
DataGrid (dgTrans) and its columns. I have a single form with one
DataGrid (dgTrans) on it. The code I have in my form load event is:

Dim dt As New DataTable("WorkOrders")

Dim colSelect As New DataColumn
Dim colStatus As New DataColumn
Dim colWO As New DataColumn
Dim colEmployee As New DataColumn

dt.Columns.Add("colSel", GetType(System.Boolean))
dt.Columns.Add(colStatus)
dt.Columns.Add(colWO)
dt.Columns.Add(colEmployee)
dgTrans.DataSource = dt

Dim gcolSelect As New DataGridBoolColumn
With gcolSelect
.Width = 15
.HeaderText = "Select"
.MappingName = "colSel"
End With
Dim gcolStatus As New DataGridTextBoxColumn
With gcolStatus
.Width = 15
.HeaderText = "Status"
.MappingName = "colStatus"
End With
Dim gcolWO As New DataGridTextBoxColumn
With gcolWO
.Width = 40
.HeaderText = "Work Order"
.MappingName = "colWO"
End With
Dim gcolEmployee As New DataGridTextBoxColumn
With gcolEmployee
.Width = 60
.HeaderText = "Employee"
.MappingName = "colEmployee"
End With

Dim ts As New DataGridTableStyle
ts.GridColumnStyles.Add(gcolSelect)
ts.GridColumnStyles.Add(gcolStatus)
ts.GridColumnStyles.Add(gcolWO)
ts.GridColumnStyles.Add(gcolEmployee)
dgTrans.TableStyles.Add(ts)

dt.Rows.Add(New Object() {False, "Open", "WO123123", "Hexman"})
dt.Rows.Add(New Object() {False, "Open", "WO123234", "S. Jones"})
dt.Rows.Add(New Object() {False, "QA", "WO123345", "B. Daley"})
dt.Rows.Add(New Object() {False, "Closed", "WO123456", "K. Genns"})
dt.Rows.Add(New Object() {False, "Open", "WO123567", "Superman"})
----------------------------------------------------------------------------------------------------------------------------------

As you can see I wanted to change the header text and width of the
grid coulumn. They are not set as I expected. The columns when
displayed are "colSel, Column1, Column2, Column3" instead of "Select,
Status, Work Order, Employee". Also the widths are not set.

I've got this working this far from Cor's Website, but I'm now stuck.
I thought I've tried everything. (I'm sure I haven't).

One other issue I'm seeing in the near future is how do I access (as
an example) a datagrid column width. In the above code it is changed
before the columns are added to the grid table styles. After the fact
how do you access that attribute? Something like:

dgTrans.TableStyles(ts).GridColumnStyles(gcolEmplo yee).width = 42

Need some help here.

Thanks,

Hexman

Dec 28 '05 #1
4 1220
Hexman wrote:
I was going along fine in my test to see how to manipulate the
DataGrid (dgTrans) and its columns. I have a single form with one
DataGrid (dgTrans) on it. The code I have in my form load event is:

Dim dt As New DataTable("WorkOrders")

Dim colSelect As New DataColumn
Dim colStatus As New DataColumn
Dim colWO As New DataColumn
Dim colEmployee As New DataColumn

dt.Columns.Add("colSel", GetType(System.Boolean))
dt.Columns.Add(colStatus)
dt.Columns.Add(colWO)
dt.Columns.Add(colEmployee)
dgTrans.DataSource = dt

Dim gcolSelect As New DataGridBoolColumn
With gcolSelect
.Width = 15
.HeaderText = "Select"
.MappingName = "colSel"
End With
Dim gcolStatus As New DataGridTextBoxColumn
With gcolStatus
.Width = 15
.HeaderText = "Status"
.MappingName = "colStatus"
End With
Dim gcolWO As New DataGridTextBoxColumn
With gcolWO
.Width = 40
.HeaderText = "Work Order"
.MappingName = "colWO"
End With
Dim gcolEmployee As New DataGridTextBoxColumn
With gcolEmployee
.Width = 60
.HeaderText = "Employee"
.MappingName = "colEmployee"
End With

Dim ts As New DataGridTableStyle
ts.GridColumnStyles.Add(gcolSelect)
ts.GridColumnStyles.Add(gcolStatus)
ts.GridColumnStyles.Add(gcolWO)
ts.GridColumnStyles.Add(gcolEmployee)
dgTrans.TableStyles.Add(ts)

dt.Rows.Add(New Object() {False, "Open", "WO123123", "Hexman"})
dt.Rows.Add(New Object() {False, "Open", "WO123234", "S. Jones"})
dt.Rows.Add(New Object() {False, "QA", "WO123345", "B. Daley"})
dt.Rows.Add(New Object() {False, "Closed", "WO123456", "K. Genns"})
dt.Rows.Add(New Object() {False, "Open", "WO123567", "Superman"})
----------------------------------------------------------------------------------------------------------------------------------

As you can see I wanted to change the header text and width of the
grid coulumn. They are not set as I expected. The columns when
displayed are "colSel, Column1, Column2, Column3" instead of "Select,
Status, Work Order, Employee". Also the widths are not set.

I've got this working this far from Cor's Website, but I'm now stuck.
I thought I've tried everything. (I'm sure I haven't).

One other issue I'm seeing in the near future is how do I access (as
an example) a datagrid column width. In the above code it is changed
before the columns are added to the grid table styles. After the fact
how do you access that attribute? Something like:

dgTrans.TableStyles(ts).GridColumnStyles(gcolEmplo yee).width = 42

Need some help here.

Thanks,

Hexman


Dim ts As New DataGridTableStyle
ts.GridColumnStyles.Add(gcolSelect)
ts.GridColumnStyles.Add(gcolStatus)
ts.GridColumnStyles.Add(gcolWO)
ts.GridColumnStyles.Add(gcolEmployee)
dgTrans.TableStyles.Add(ts)

You need to add:
ts.MappingName = "WorkOrders"

You have to tell the tablestyle which datatable it is mapping. This is
so you can have several different styles for different tables.

Hope it helps
Chris
Dec 28 '05 #2
On Wed, 28 Dec 2005 00:28:20 -0500, I Don't Like Spam <no@spam.com>
wrote:
Hexman wrote:
I was going along fine in my test to see how to manipulate the
DataGrid (dgTrans) and its columns. I have a single form with one
DataGrid (dgTrans) on it. The code I have in my form load event is:

Dim dt As New DataTable("WorkOrders")

Dim colSelect As New DataColumn
Dim colStatus As New DataColumn
Dim colWO As New DataColumn
Dim colEmployee As New DataColumn

dt.Columns.Add("colSel", GetType(System.Boolean))
dt.Columns.Add(colStatus)
dt.Columns.Add(colWO)
dt.Columns.Add(colEmployee)
dgTrans.DataSource = dt

Dim gcolSelect As New DataGridBoolColumn
With gcolSelect
.Width = 15
.HeaderText = "Select"
.MappingName = "colSel"
End With
Dim gcolStatus As New DataGridTextBoxColumn
With gcolStatus
.Width = 15
.HeaderText = "Status"
.MappingName = "colStatus"
End With
Dim gcolWO As New DataGridTextBoxColumn
With gcolWO
.Width = 40
.HeaderText = "Work Order"
.MappingName = "colWO"
End With
Dim gcolEmployee As New DataGridTextBoxColumn
With gcolEmployee
.Width = 60
.HeaderText = "Employee"
.MappingName = "colEmployee"
End With

Dim ts As New DataGridTableStyle
ts.GridColumnStyles.Add(gcolSelect)
ts.GridColumnStyles.Add(gcolStatus)
ts.GridColumnStyles.Add(gcolWO)
ts.GridColumnStyles.Add(gcolEmployee)
dgTrans.TableStyles.Add(ts)

dt.Rows.Add(New Object() {False, "Open", "WO123123", "Hexman"})
dt.Rows.Add(New Object() {False, "Open", "WO123234", "S. Jones"})
dt.Rows.Add(New Object() {False, "QA", "WO123345", "B. Daley"})
dt.Rows.Add(New Object() {False, "Closed", "WO123456", "K. Genns"})
dt.Rows.Add(New Object() {False, "Open", "WO123567", "Superman"})
----------------------------------------------------------------------------------------------------------------------------------

As you can see I wanted to change the header text and width of the
grid coulumn. They are not set as I expected. The columns when
displayed are "colSel, Column1, Column2, Column3" instead of "Select,
Status, Work Order, Employee". Also the widths are not set.

I've got this working this far from Cor's Website, but I'm now stuck.
I thought I've tried everything. (I'm sure I haven't).

One other issue I'm seeing in the near future is how do I access (as
an example) a datagrid column width. In the above code it is changed
before the columns are added to the grid table styles. After the fact
how do you access that attribute? Something like:

dgTrans.TableStyles(ts).GridColumnStyles(gcolEmplo yee).width = 42

Need some help here.

Thanks,

Hexman


Dim ts As New DataGridTableStyle
ts.GridColumnStyles.Add(gcolSelect)
ts.GridColumnStyles.Add(gcolStatus)
ts.GridColumnStyles.Add(gcolWO)
ts.GridColumnStyles.Add(gcolEmployee)
dgTrans.TableStyles.Add(ts)

You need to add:
ts.MappingName = "WorkOrders"

You have to tell the tablestyle which datatable it is mapping. This is
so you can have several different styles for different tables.

Hope it helps
Chris

Thank you Chris. I see I'm going to have to read much more on the
datagrid and datasources. So much to read - so little time.

Adding table style mapping name solved the problem of setting the
attributes of the column, but another issue just reared its head.
Only the first column ("Select") is visible in the grid. Any idea on
this one? (Check for "IsVisible"?)

I see the DataGrid as a most useful control when working with data
sets. I'd like to read "from the ground up" on it. Can you recommend
a book or online source?

Still would like to know how to access the attributes after they have
been established as in:

dgTrans.TableStyles(ts).GridColumnStyles(gcolEmplo yee).width = 42

Thanks once again,

Hexman

Dec 28 '05 #3
Hexman wrote:
On Wed, 28 Dec 2005 00:28:20 -0500, I Don't Like Spam <no@spam.com>
wrote:

Hexman wrote:
I was going along fine in my test to see how to manipulate the
DataGrid (dgTrans) and its columns. I have a single form with one
DataGrid (dgTrans) on it. The code I have in my form load event is:

Dim dt As New DataTable("WorkOrders")

Dim colSelect As New DataColumn
Dim colStatus As New DataColumn
Dim colWO As New DataColumn
Dim colEmployee As New DataColumn

dt.Columns.Add("colSel", GetType(System.Boolean))
dt.Columns.Add(colStatus)
dt.Columns.Add(colWO)
dt.Columns.Add(colEmployee)
dgTrans.DataSource = dt

Dim gcolSelect As New DataGridBoolColumn
With gcolSelect
.Width = 15
.HeaderText = "Select"
.MappingName = "colSel"
End With
Dim gcolStatus As New DataGridTextBoxColumn
With gcolStatus
.Width = 15
.HeaderText = "Status"
.MappingName = "colStatus"
End With
Dim gcolWO As New DataGridTextBoxColumn
With gcolWO
.Width = 40
.HeaderText = "Work Order"
.MappingName = "colWO"
End With
Dim gcolEmployee As New DataGridTextBoxColumn
With gcolEmployee
.Width = 60
.HeaderText = "Employee"
.MappingName = "colEmployee"
End With

Dim ts As New DataGridTableStyle
ts.GridColumnStyles.Add(gcolSelect)
ts.GridColumnStyles.Add(gcolStatus)
ts.GridColumnStyles.Add(gcolWO)
ts.GridColumnStyles.Add(gcolEmployee)
dgTrans.TableStyles.Add(ts)

dt.Rows.Add(New Object() {False, "Open", "WO123123", "Hexman"})
dt.Rows.Add(New Object() {False, "Open", "WO123234", "S. Jones"})
dt.Rows.Add(New Object() {False, "QA", "WO123345", "B. Daley"})
dt.Rows.Add(New Object() {False, "Closed", "WO123456", "K. Genns"})
dt.Rows.Add(New Object() {False, "Open", "WO123567", "Superman"})
----------------------------------------------------------------------------------------------------------------------------------

As you can see I wanted to change the header text and width of the
grid coulumn. They are not set as I expected. The columns when
displayed are "colSel, Column1, Column2, Column3" instead of "Select,
Status, Work Order, Employee". Also the widths are not set.

I've got this working this far from Cor's Website, but I'm now stuck.
I thought I've tried everything. (I'm sure I haven't).

One other issue I'm seeing in the near future is how do I access (as
an example) a datagrid column width. In the above code it is changed
before the columns are added to the grid table styles. After the fact
how do you access that attribute? Something like:

dgTrans.TableStyles(ts).GridColumnStyles(gcolEmplo yee).width = 42

Need some help here.

Thanks,

Hexman


Dim ts As New DataGridTableStyle
ts.GridColumnStyles.Add(gcolSelect)
ts.GridColumnStyles.Add(gcolStatus)
ts.GridColumnStyles.Add(gcolWO)
ts.GridColumnStyles.Add(gcolEmployee)
dgTrans.TableStyles.Add(ts)

You need to add:
ts.MappingName = "WorkOrders"

You have to tell the tablestyle which datatable it is mapping. This is
so you can have several different styles for different tables.

Hope it helps
Chris


Thank you Chris. I see I'm going to have to read much more on the
datagrid and datasources. So much to read - so little time.

Adding table style mapping name solved the problem of setting the
attributes of the column, but another issue just reared its head.
Only the first column ("Select") is visible in the grid. Any idea on
this one? (Check for "IsVisible"?)

I see the DataGrid as a most useful control when working with data
sets. I'd like to read "from the ground up" on it. Can you recommend
a book or online source?

Still would like to know how to access the attributes after they have
been established as in:

dgTrans.TableStyles(ts).GridColumnStyles(gcolEmplo yee).width = 42

Thanks once again,

Hexman


Sorry, I learned how to use the datagrid by trial and error... don't
know of any great online resources. As to your problem this is because
of how you created your datacolumn

Dim colSelect As New DataColumn
Dim colStatus As New DataColumn
Dim colWO As New DataColumn
Dim colEmployee As New DataColumn

dt.Columns.Add("colSel", GetType(System.Boolean))
dt.Columns.Add(colStatus)
dt.Columns.Add(colWO)
dt.Columns.Add(colEmployee)
dgTrans.DataSource = dt

First off, you create a colSelect, but never use it. I prefer using
this method to create datacolumns:

dt.Columns.Add("colSel", GetType(System.Boolean))

Now when you created this column, you gave it a name. This is how the
tablestyle knows which column to map, and why it is the only one showing
up. If you give the other 3 columns the correct names, they will show
up also.

Chris
Dec 28 '05 #4
On Wed, 28 Dec 2005 12:40:37 -0500, Chris <no@spam.com> wrote:
Hexman wrote:
On Wed, 28 Dec 2005 00:28:20 -0500, I Don't Like Spam <no@spam.com>
wrote:

Hexman wrote:

I was going along fine in my test to see how to manipulate the
DataGrid (dgTrans) and its columns. I have a single form with one
DataGrid (dgTrans) on it. The code I have in my form load event is:

Dim dt As New DataTable("WorkOrders")

Dim colSelect As New DataColumn
Dim colStatus As New DataColumn
Dim colWO As New DataColumn
Dim colEmployee As New DataColumn

dt.Columns.Add("colSel", GetType(System.Boolean))
dt.Columns.Add(colStatus)
dt.Columns.Add(colWO)
dt.Columns.Add(colEmployee)
dgTrans.DataSource = dt

Dim gcolSelect As New DataGridBoolColumn
With gcolSelect
.Width = 15
.HeaderText = "Select"
.MappingName = "colSel"
End With
Dim gcolStatus As New DataGridTextBoxColumn
With gcolStatus
.Width = 15
.HeaderText = "Status"
.MappingName = "colStatus"
End With
Dim gcolWO As New DataGridTextBoxColumn
With gcolWO
.Width = 40
.HeaderText = "Work Order"
.MappingName = "colWO"
End With
Dim gcolEmployee As New DataGridTextBoxColumn
With gcolEmployee
.Width = 60
.HeaderText = "Employee"
.MappingName = "colEmployee"
End With

Dim ts As New DataGridTableStyle
ts.GridColumnStyles.Add(gcolSelect)
ts.GridColumnStyles.Add(gcolStatus)
ts.GridColumnStyles.Add(gcolWO)
ts.GridColumnStyles.Add(gcolEmployee)
dgTrans.TableStyles.Add(ts)

dt.Rows.Add(New Object() {False, "Open", "WO123123", "Hexman"})
dt.Rows.Add(New Object() {False, "Open", "WO123234", "S. Jones"})
dt.Rows.Add(New Object() {False, "QA", "WO123345", "B. Daley"})
dt.Rows.Add(New Object() {False, "Closed", "WO123456", "K. Genns"})
dt.Rows.Add(New Object() {False, "Open", "WO123567", "Superman"})
----------------------------------------------------------------------------------------------------------------------------------

As you can see I wanted to change the header text and width of the
grid coulumn. They are not set as I expected. The columns when
displayed are "colSel, Column1, Column2, Column3" instead of "Select,
Status, Work Order, Employee". Also the widths are not set.

I've got this working this far from Cor's Website, but I'm now stuck.
I thought I've tried everything. (I'm sure I haven't).

One other issue I'm seeing in the near future is how do I access (as
an example) a datagrid column width. In the above code it is changed
before the columns are added to the grid table styles. After the fact
how do you access that attribute? Something like:

dgTrans.TableStyles(ts).GridColumnStyles(gcolEmplo yee).width = 42

Need some help here.

Thanks,

Hexman
Dim ts As New DataGridTableStyle
ts.GridColumnStyles.Add(gcolSelect)
ts.GridColumnStyles.Add(gcolStatus)
ts.GridColumnStyles.Add(gcolWO)
ts.GridColumnStyles.Add(gcolEmployee)
dgTrans.TableStyles.Add(ts)

You need to add:
ts.MappingName = "WorkOrders"

You have to tell the tablestyle which datatable it is mapping. This is
so you can have several different styles for different tables.

Hope it helps
Chris


Thank you Chris. I see I'm going to have to read much more on the
datagrid and datasources. So much to read - so little time.

Adding table style mapping name solved the problem of setting the
attributes of the column, but another issue just reared its head.
Only the first column ("Select") is visible in the grid. Any idea on
this one? (Check for "IsVisible"?)

I see the DataGrid as a most useful control when working with data
sets. I'd like to read "from the ground up" on it. Can you recommend
a book or online source?

Still would like to know how to access the attributes after they have
been established as in:

dgTrans.TableStyles(ts).GridColumnStyles(gcolEmplo yee).width = 42

Thanks once again,

Hexman


Sorry, I learned how to use the datagrid by trial and error... don't
know of any great online resources. As to your problem this is because
of how you created your datacolumn

Dim colSelect As New DataColumn
Dim colStatus As New DataColumn
Dim colWO As New DataColumn
Dim colEmployee As New DataColumn

dt.Columns.Add("colSel", GetType(System.Boolean))
dt.Columns.Add(colStatus)
dt.Columns.Add(colWO)
dt.Columns.Add(colEmployee)
dgTrans.DataSource = dt

First off, you create a colSelect, but never use it. I prefer using
this method to create datacolumns:

dt.Columns.Add("colSel", GetType(System.Boolean))

Now when you created this column, you gave it a name. This is how the
tablestyle knows which column to map, and why it is the only one showing
up. If you give the other 3 columns the correct names, they will show
up also.

Chris


Thanks for sharing your knowledge. Looks as if I will be learning by
trial and error also, but with the assistance of this newsgroup.

By using your suggestions, I've completed the task I needed to.

Now on to the next task.........

Thanks alot,

Hexman
Dec 28 '05 #5

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

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
14
by: Jack Kaufmann | last post by:
I am trying to verify a datagrid in which there must be an entry in both columns of any new row, and those values must be greater than the corresponding values in the previous row. It is pretty...
0
by: Frank | last post by:
I have a boolean field tied to a datagrid, which is represented in the grid by a checkbox. To select the checkbox however, the user has to click on the field twice, once to select the field, and...
3
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control,...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
4
by: Reney | last post by:
I have a very weird problem in updating my datagrid. Please help me to solve it. The datagrid is tied to a dataset table with five columns. Three of them are primary key and the other two columns...
14
by: Brett Sinclair | last post by:
Hello everybody I'm still on the learning curve here...and from what I read, I created inherited datagrid class so I could have icons, combobox...etc in the columns of my datagrid. The grid...
10
by: mark | last post by:
I have a simple windows application that has a function to read a csv file and enter the values into an array A as double(,). Also, an instance of form 2 (which has a DataGrid) is created and the...
9
by: rn5a | last post by:
A DataGrid is populated with the records existing in a database. Each of the row in this DataGrid has a ButtonColumn. Assume that the DataGrid displays 10 records (i.e. 10 DataGridItems/rows). Each...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.