473,498 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding ColumnStyles to DataGrid

Hi,

I'm trying to add column styles to a datagrid--first time I've done this in
code. I have a datagrid and have added a new table style to it in the
designer. I've set the tablestyle's mapping name to the name of my dataset
table. Then this is my code for adding columns:

With dgdInventory.TableStyles.Item(0).GridColumnStyles
Dim colIsAP As New DataGridBoolColumn()
With colIsAP
.Alignment = HorizontalAlignment.Center
.HeaderText = "A/P"
.Width = 40
.MappingName = "IsActivityPac"
.ReadOnly = True
.NullText = ""
End With
.Add(colIsAP)

Dim colItemNumber As New DataGridTextBoxColumn()
With colItemNumber
.Alignment = HorizontalAlignment.Left
.HeaderText = "Item #"
.Width = 75
.MappingName = "ItemNumber"
.NullText = ""
End With
.Add(colItemNumber)

Dim colItemDescription As New DataGridTextBoxColumn()
With colItemNumber
.Alignment = HorizontalAlignment.Left
.HeaderText = "Description"
.Width = 200
.MappingName = "ItemDescription"
.NullText = ""
End With
.Add(colItemDescription)

End With

.... and so on: I have seven columns that are set up this way. When I load
the form, only the first and last columns show up, no matter what order I
add them. I can successfully do this through the designer, but is something
wrong with my code?

Thanks,
Nathan
Nov 21 '05 #1
7 1069
Nathan,

Assuming that you have added it because you see the first and last columns,
the first thing I think about is with this always the case sensivity of the
mappingnames.

Are they in the correct case?

Cor
Nov 21 '05 #2
Thanks, Cor. Yes, the mapping names are in the correct case.

If I comment out the last column addition, then I see the next-to-last
column instead. Whatever columns I have listed first and last are the ones
to show up in the grid.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:ua**************@TK2MSFTNGP14.phx.gbl...
Nathan,

Assuming that you have added it because you see the first and last
columns, the first thing I think about is with this always the case
sensivity of the mappingnames.

Are they in the correct case?

Cor

Nov 21 '05 #3
Nathan,

You are sure that your datagrid is not just to small to show them all?

Cor
Nov 21 '05 #4
The datagrid is 600 pixels wide. The two columns that show do not show with
the width assigned to them -- they are the default width. Lots of blank
space.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2*****************@tk2msftngp13.phx.gbl...
Nathan,

You are sure that your datagrid is not just to small to show them all?

Cor

Nov 21 '05 #5
Nathan,

You don't know how much I don't like that "With", I tested your sample and
saw it only when I had deleted the "With" and replaced the code as you told
you did.

Have a look at it in your code (my test sample is below, however not
needed)..

"With colItemNumber"

:-)

I hope this helps?

Cor

\\\
Dim dt As New DataTable("Nathan")
dt.Columns.Add("IsActivityPac", GetType(System.Boolean))
dt.Columns.Add("ItemNumber", GetType(System.Int32))
dt.Columns.Add("ItemDescription", GetType(System.String))
For i As Integer = 0 To 9
dt.Rows.Add(dt.NewRow)
Dim dr As DataRow = dt.Rows(i)
dr(0) = True
dr(1) = i
dr(2) = ChrW(i + 65)
Next
dgdInventory.DataSource = dt
Dim dgt As New DataGridTableStyle
dgt.MappingName = "Nathan"

Dim colIsAP As New DataGridBoolColumn
colIsAP.Alignment = HorizontalAlignment.Center
colIsAP.HeaderText = "A/P"
colIsAP.Width = 40
colIsAP.MappingName = "IsActivityPac"
colIsAP.ReadOnly = True
colIsAP.NullText = ""
dgt.GridColumnStyles.Add(colIsAP)

Dim colItemNumber As New DataGridTextBoxColumn
colItemNumber.Alignment = HorizontalAlignment.Left
colItemNumber.HeaderText = "Item #"
colItemNumber.Width = 75
colItemNumber.MappingName = "ItemNumber"
colItemNumber.NullText = ""
dgt.GridColumnStyles.Add(colItemNumber)

Dim colItemDescription As New DataGridTextBoxColumn
colItemDescription.Alignment = HorizontalAlignment.Left
colItemDescription.HeaderText = "Description"
colItemDescription.Width = 200
colItemDescription.MappingName = "ItemDescription"
colItemDescription.NullText = ""
dgt.GridColumnStyles.Add(colItemDescription)
dgdInventory.TableStyles.Add(dgt)
///

Nov 21 '05 #6
Urgh! I found the error. It was not because I was using "With", but
because just copied and pasted the With blocks, but forgot to change the
With colName each time. Thanks for your help, or I may not have seen it.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e0****************@TK2MSFTNGP14.phx.gbl...
Nathan,

You don't know how much I don't like that "With", I tested your sample and
saw it only when I had deleted the "With" and replaced the code as you
told you did.

Have a look at it in your code (my test sample is below, however not
needed)..

"With colItemNumber"

:-)

I hope this helps?

Cor

\\\
Dim dt As New DataTable("Nathan")
dt.Columns.Add("IsActivityPac", GetType(System.Boolean))
dt.Columns.Add("ItemNumber", GetType(System.Int32))
dt.Columns.Add("ItemDescription", GetType(System.String))
For i As Integer = 0 To 9
dt.Rows.Add(dt.NewRow)
Dim dr As DataRow = dt.Rows(i)
dr(0) = True
dr(1) = i
dr(2) = ChrW(i + 65)
Next
dgdInventory.DataSource = dt
Dim dgt As New DataGridTableStyle
dgt.MappingName = "Nathan"

Dim colIsAP As New DataGridBoolColumn
colIsAP.Alignment = HorizontalAlignment.Center
colIsAP.HeaderText = "A/P"
colIsAP.Width = 40
colIsAP.MappingName = "IsActivityPac"
colIsAP.ReadOnly = True
colIsAP.NullText = ""
dgt.GridColumnStyles.Add(colIsAP)

Dim colItemNumber As New DataGridTextBoxColumn
colItemNumber.Alignment = HorizontalAlignment.Left
colItemNumber.HeaderText = "Item #"
colItemNumber.Width = 75
colItemNumber.MappingName = "ItemNumber"
colItemNumber.NullText = ""
dgt.GridColumnStyles.Add(colItemNumber)

Dim colItemDescription As New DataGridTextBoxColumn
colItemDescription.Alignment = HorizontalAlignment.Left
colItemDescription.HeaderText = "Description"
colItemDescription.Width = 200
colItemDescription.MappingName = "ItemDescription"
colItemDescription.NullText = ""
dgt.GridColumnStyles.Add(colItemDescription)
dgdInventory.TableStyles.Add(dgt)
///

Nov 21 '05 #7
Nathan,

I did not say that it was because of with, however using the with gives more
change on this kind of errors, and therefore I don't like it.

You copied it and did not see the error, however I gave you the change to
see that yourself.

:-)

Cor
Nov 21 '05 #8

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

Similar topics

2
9990
by: Jim | last post by:
In my Win App, I have a datagrid that's bound to a dataset. When the form loads, the datagrid fills. How can I add an empty row to the end of the datagrid during a button click (similar to...
2
3613
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
5
1516
by: Phil Townsend | last post by:
I need to add a button to a datagrid. I have tried using the ButtonColumn and have also tried adding a button to a templatecolumn > itemtemplate. Whatever I have tried doesn't work, nor does it...
3
4854
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
3257
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...
2
2418
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via...
6
6804
by: Atley | last post by:
I have a Datagrid I have created, it's datasource is an XML Dataset that I have created. That form worked perfectly, until I had to add a column to the table... I did it in my database, it shows...
3
3130
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
2
3538
by: Flack | last post by:
Hey guys, I have a DataGrid and DataTable field in my class : private ImageDataGrid dataGrid1; //ImageDataGrid extends dataGrid and just overides OnMouseDown private DataTable dt = new...
0
7004
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
7167
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
7208
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
6890
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
5464
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,...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4593
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
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
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 ...

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.