Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2004

Tip: Looking for answers? Try searching our database.

DataGrid - Inserting Columns

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dennis - 21 Oct 2004 02:03 GMT
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.GridColumnStyles(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.GridColumnStyles(i))
           i = i + 1
      End While
      ts.Dispose()
      Me.Refresh()
Signature

Dennis in Houston

Cor Ligthert - 21 Oct 2004 11:00 GMT
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" <Dennis@discussions.microsoft.com>
>I have a class which inherits from DataGrid and it is bound to a a
>DataTable.
[quoted text clipped - 31 lines]
>       ts.Dispose()
>       Me.Refresh()
Dennis - 21 Oct 2004 23:35 GMT
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.

> Dennis,
>
[quoted text clipped - 53 lines]
> >       ts.Dispose()
> >       Me.Refresh()

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.