473,464 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Adding a fresh column to a datagrid

I want to add a fresh column to a datagrid that is bound to a datasource

i want it to be the first column on the datagrid so that i can number each
row 1,2,3,4.... etc. (but i have no need to store this within my database)

how do i add an empty column?
Thanks
Mike Fellows

Nov 20 '05 #1
2 2291
Mike,

You need to add a datacolumn to the datatable you are showing in the
datagrid. Add a tablestyle to the datagrid to adjust the order the columns
are displayed.

To add a column to data table
Dim dcNew As New DataColumn("Numbered", GetType(Integer))

daCustomer.Fill(ds, "Clients")

ds.Tables("Clients").Columns.Add(dcNew)

Dim x As Integer

For x = 0 To ds.Tables("Clients").Rows.Count - 1

Dim dr As DataRow = ds.Tables("Clients").Rows(x)

dr.BeginEdit()

dr.Item("Numbered") = x

dr.EndEdit()

Next

SetupData()

To add a table style

Private Sub SetupData()

Dim ts As New DataGridTableStyle

ts.MappingName = "Clients"

Dim col As New DataGridTextBoxColumn

With col

..MappingName = "Numbered"

..HeaderText = "Numbered"

..Width = 50

End With

Dim colPhone As New DataGridTextBoxColumn

With colPhone

..MappingName = "PhoneNumber"

..HeaderText = "Phone Number"

..Width = 200

End With

Dim colName As New DataGridTextBoxColumn

With colName

..MappingName = "LastName"

..HeaderText = "Name"

..Width = 250

End With

ts.GridColumnStyles.Add(col)

ts.GridColumnStyles.Add(colPhone)

ts.GridColumnStyles.Add(colName)

DataGrid1.TableStyles.Add(ts)

ts = Nothing

colPhone = Nothing

colName = Nothing

End Sub

Ken
-----------------
"Mike Fellows" <mi*************@equityhouse.co.uk.SPAM> wrote in message
news:RX***************@newsfep3-gui.server.ntli.net...
I want to add a fresh column to a datagrid that is bound to a datasource

i want it to be the first column on the datagrid so that i can number each
row 1,2,3,4.... etc. (but i have no need to store this within my database)

how do i add an empty column?
Thanks
Mike Fellows

Nov 20 '05 #2
You need to do this thing programmatically.. I mean as runtime.

You need to write simple DATAGRID code to add a column, and compute
serial number by incrementing a loop counter and inserting that value in
the CELL for that newly added column.

Hope this makes sense. I am in rush, so cannot write code... rightnow...
but later if u need let me know.

Keyur Shah
Verizon Communications
732-423-0745

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3

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

Similar topics

5
by: Sue | last post by:
On code-behind page: (attributes set programatically for each of these elements) linkbutton added to tablecell textbox added to tablecell tablecells added to tablerow tablerow added to table...
2
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...
6
by: Robert Schuldenfrei | last post by:
Dear NG, After being away from C# programming for a spell, I am trying my hand at what should be a simple task. I have been hitting my head against the wall this morning. I have a simple order...
3
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...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
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...
2
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...
1
by: RN | last post by:
Hi. I used this article to add a template column to a datagrid that is entirely created with code: ...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
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,...
1
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
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.