PC Review


Reply
Thread Tools Rate Thread

DataGrid - Inserting Columns

 
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      21st Oct 2004
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()
--
Dennis in Houston
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      21st Oct 2004
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" <(E-Mail Removed)>
>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()
> --
> Dennis in Houston



 
Reply With Quote
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      21st Oct 2004
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" <(E-Mail Removed)>
> >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()
> > --
> > Dennis in Houston

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid, binded columns and unbinded columns =?Utf-8?B?S2VycnkgTW9vcm1hbg==?= Microsoft VB .NET 4 28th Apr 2006 06:02 AM
How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the datagrid Update event. Daniel Roth Microsoft Dot NET Framework 0 5th Apr 2005 04:54 AM
Adding/Inserting rows and columns to DataGrid =?Utf-8?B?VmljdG9y?= Microsoft Dot NET Framework Forms 1 5th Mar 2004 01:41 PM
Inserting unbound columns in a DataGrid jy836 Microsoft VB .NET 0 29th Jan 2004 05:17 PM
DataGrid Component | Displaying columns of a DataSet as Rows in a DataGrid ? Diego TERCERO Microsoft C# .NET 3 19th Dec 2003 02:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:03 AM.