DataGrid - Inserting Columns

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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,

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
 
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.
 
Back
Top