473,405 Members | 2,310 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,405 software developers and data experts.

DataGrid - Inserting Columns

I have a class which inherits from DataGrid and it is bound to a a DataTable.
I have defined the GridColumnStyles I want to display. Also, I have added an
"InsertCol" to my class whidh has the code below. It works great and inserts
a column in the Datagrid whereever I specify. However, it seems the code is
like using 16 pound hammer to drive a tack..is there a shorter way?

Note: v_currentTableStyle is the current TableStyle for the DataGrid display

Public Sub InsertCol(ByVal colstyle As Object, BeforeCol As Integer)
Dim i, j As Integer
Dim ts As New DataGridTableStyle
i = beforecol
j = i
While i < v_currentTableStyle.GridColumnStyles.Count
ts.GridColumnStyles.Add(v_currentTableStyle.GridCo lumnStyles(j))
v_currentTableStyle.GridColumnStyles.RemoveAt(j)
i = i + 1
End While
add_GridColumnStyle(colstyle) 'a routine that adds different colstyles
j = ts.GridColumnStyles.Count
i = 0
While i < j
v_currentTableStyle.GridColumnStyles.Add(ts.GridCo lumnStyles(i))
i = i + 1
End While
ts.Dispose()
Me.Refresh()
--
Dennis in Houston
Nov 21 '05 #1
2 1345
Dennis,

I see not much as better solution, some things you can do is that you only
have to copy the columns after the insert column, add the new one and add
the saved ones again.

For that it is easier to use the "for index", just some typing as a kind of
pseudo

for i as integer = insertcol to endcol - 1
save and remove columns
next
add new column
for i as integer = insertcol + 1 to (endcol + endcolsaved) - 1
add again saved
next

I hope this gives an idea?

Cor

"Dennis" <De****@discussions.microsoft.com>
I have a class which inherits from DataGrid and it is bound to a a
DataTable.
I have defined the GridColumnStyles I want to display. Also, I have added
an
"InsertCol" to my class whidh has the code below. It works great and
inserts
a column in the Datagrid whereever I specify. However, it seems the code
is
like using 16 pound hammer to drive a tack..is there a shorter way?

Note: v_currentTableStyle is the current TableStyle for the DataGrid
display

Public Sub InsertCol(ByVal colstyle As Object, BeforeCol As Integer)
Dim i, j As Integer
Dim ts As New DataGridTableStyle
i = beforecol
j = i
While i < v_currentTableStyle.GridColumnStyles.Count

ts.GridColumnStyles.Add(v_currentTableStyle.GridCo lumnStyles(j))
v_currentTableStyle.GridColumnStyles.RemoveAt(j)
i = i + 1
End While
add_GridColumnStyle(colstyle) 'a routine that adds different
colstyles
j = ts.GridColumnStyles.Count
i = 0
While i < j

v_currentTableStyle.GridColumnStyles.Add(ts.GridCo lumnStyles(i))
i = i + 1
End While
ts.Dispose()
Me.Refresh()
--
Dennis in Houston

Nov 21 '05 #2
Thanks Cor. This will shorten my code somewhat. Very much appreciate all
the replies that you provide on this newsgroup. I usually read all questions
and replies every evening as I find it a great way to learn. By the way, on
your discussion about globalizaiton for dates, etc., I agree with you that
whenever possible, one should write routines that can be used globally...I
think the others missed your point.

"Cor Ligthert" wrote:
Dennis,

I see not much as better solution, some things you can do is that you only
have to copy the columns after the insert column, add the new one and add
the saved ones again.

For that it is easier to use the "for index", just some typing as a kind of
pseudo

for i as integer = insertcol to endcol - 1
save and remove columns
next
add new column
for i as integer = insertcol + 1 to (endcol + endcolsaved) - 1
add again saved
next

I hope this gives an idea?

Cor

"Dennis" <De****@discussions.microsoft.com>
I have a class which inherits from DataGrid and it is bound to a a
DataTable.
I have defined the GridColumnStyles I want to display. Also, I have added
an
"InsertCol" to my class whidh has the code below. It works great and
inserts
a column in the Datagrid whereever I specify. However, it seems the code
is
like using 16 pound hammer to drive a tack..is there a shorter way?

Note: v_currentTableStyle is the current TableStyle for the DataGrid
display

Public Sub InsertCol(ByVal colstyle As Object, BeforeCol As Integer)
Dim i, j As Integer
Dim ts As New DataGridTableStyle
i = beforecol
j = i
While i < v_currentTableStyle.GridColumnStyles.Count

ts.GridColumnStyles.Add(v_currentTableStyle.GridCo lumnStyles(j))
v_currentTableStyle.GridColumnStyles.RemoveAt(j)
i = i + 1
End While
add_GridColumnStyle(colstyle) 'a routine that adds different
colstyles
j = ts.GridColumnStyles.Count
i = 0
While i < j

v_currentTableStyle.GridColumnStyles.Add(ts.GridCo lumnStyles(i))
i = i + 1
End While
ts.Dispose()
Me.Refresh()
--
Dennis in Houston


Nov 21 '05 #3

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

Similar topics

5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
0
by: Paolo Tardivel via DotNetMonster.com | last post by:
I have a databound datagrid containing template columns which allow editing of the values contained in the datagrid through the use of text boxes. One of the fields in the datagrid displays the...
0
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is...
9
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
10
by: Nick | last post by:
Hello, Please pardon my ignorance as I'm sure this is easy to do. I have a datagrid where I want to let the user delete columns. I added a context menu to the datagrid that has a delete option....
2
by: Krishna | last post by:
Hi, I have developed a for dataentry by using datagird in C# windows application, I am using combocolumns, textbox columns for the same, two readonly textboxcolumns for those readonly columns i...
13
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever...
23
by: tanya2001 | last post by:
hi all.. I am trying to update my datagrid in my webform...but its not getting updated..though in the database it removing the <null> and inserting a blank field....its not taking the input which m...
0
by: RN1 | last post by:
A Form has a few fields along with a Submit button & a DataGrid. The fields & the Submit Button are encapsulated in a Panel named pnlDataEntry & the DataGrid is encapsulated in a Panel named...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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...

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.