Datatable.Compute and Sorting

  • Thread starter Thread starter scorpion53061
  • Start date Start date
S

scorpion53061

Can I use this to sort a datatable or can you suggest another way to sort it
without using a dataview? I have a situation where I need to do this without
a dataview due to other facets it will affect within my application.

When I try

opends1.Tables(0).Compute("ORDER by " & sortterm & "","") it says I am
missing the operand after "by".
 
Sure no problem.

The problem is that this is a globally declared dataset that needed the data
in the sort order for the report writing functions in another module. I
could have used the dataview but then when they went to write the report the
order would be wrong. If I change to a globally declared dataview I was
concerned what effect it would have on my excel and word reports (I have
never tried to write a dataview to an excel spreadsheet so it may be
possible).

Another problem has been encountered that my interest you.

DATEOR is a date column in the dataset. The task is to format the column to
get the (12:00:00) time off and color the box is the value of backorders > 0
and days > 90.

However though it is appearing as I wanted it too and sorting as I requested
it to, the yellow has been lost.

Can you suggest what I am doing wrong?

I have a class for my datagrid called ClassDatagridFormat

one if ...Then procedure says:

If Me.MappingName = "DATEOR" Then
Dim ObjVal As Object
ObjVal = Me.GetColumnValueAtRow(curmngrSrc, RowNumber)
Dim days As Integer
Dim cellValue As String
cellValue = CType(ObjVal, Date).ToShortDateString
days = DateDiff(DateInterval.Day, CDate(cellValue),
CDate(timeofrecord))
If days >= 90 And backorders = 0 Then
BackColorBrush = System.Drawing.Brushes.Yellow
End If
If days >= 90 And backorders > 0 Then
BackColorBrush = System.Drawing.Brushes.White
End If
If days < 90 Then
BackColorBrush = System.Drawing.Brushes.White
End If
ForeColorBrush = Brushes.Black
MyBase.Paint(graph, rectbounds, curmngrSrc, RowNumber, _
BackColorBrush, ForeColorBrush, AlignmentLeft)
'DataAlignment = HorizontalAlignment.Center
graph.FillRectangle(BackColorBrush, rectbounds)
'draw the value
Dim s As String = Me.GetColumnValueAtRow([curmngrSrc],
RowNumber).ToString()
Dim r As New RectangleF(rectbounds.X, rectbounds.Y,
rectbounds.Width, rectbounds.Height)
graph.DrawString(s, MyBase.TextBox.Font, ForeColorBrush, r,
mDrawTxt)
Me.TextBox.ReadOnly = True
mTxtAlign = HorizontalAlignment.Left
mDrawTxt.LineAlignment = StringAlignment.Center
'Exit Sub
End If

The call in the form to this Class is :

Dim myCurrencyManger As CurrencyManager = CType(Me.BindingContext(opends1),
CurrencyManager)
Dim proprtyDescriptorName As PropertyDescriptor =
myCurrencyManger.GetItemProperties()(opends1.Tables(0).TableName)
Dim myDateDescriptor As PropertyDescriptor =
myCurrencyManger.GetItemProperties()("DATEOR")
Dim myDateStyle = New DataGridTextBoxColumn(myDateDescriptor, "G")
myDateStyle.MappingName = "DATEOR"
myDateStyle.HeaderText = "DATE"
myDateStyle.Width = 75
myDateStyle.Format = "d"

By the way, are you ready for the "article"?

The problem is that this dataset is declared globally
 
Hi Scorpion,

What you can do I think is this in completly pseudo

Make a dataview from your table
Make a clone from your table
Make a loop through your dataview to your new datatable something as this
(also pseudo)
for i as integer = 0 to dataview.rows.count - 1
dim dr as datarow = dataview.table.newrow
for y as integer = 0 to dataview.rows(i).items.count - 1
' this to prevent keysproblems
dr(y) = dv(i)(y)
next
newdatatable.add(dr)
next

Just as an idea.

Cor
 
Back
Top