The Management result view is nothing more than a formatted text. You need to receive DataTable
, then
dim columns as new Dictionary(of int, int) ' save col index / col width info
for i as integer = 0 to DataTable.Columns.count - 1
columns.Add(i, 1)
next
dim data as new List(of List(of string))
' preload you values and calculate width
For rows as int = 0 to DataTable.Rows.Count-1
for cols as integer = 0 to DataTable.Columns.Count - 1
dim cl as new List(of string) ' Save your string values here
if not isDbnull(DataTable.Rows(rows)(cols)) Then
dim val as string = convert.toString()(DataTable.Rows(rows)(cols))
if val.Length > columns(cols) Then
columns(cols) = val.Length
end if
cl.Add(val)
else
cl.Add(string.empty)
end if
next
data.Add(cl)
next
Now, print your output
dim sb as new StringBuilder()
' Do the header
for i as integer = 0 to Datatable.Columns.count -1
sb.Append(Datatable.Columns(i).ColumnName.PadRight(columns(i), "_"))
sb.Append(" ") ' space between columns
next
sb.Append(Environment.NewLine)
' Now Data
for each l as list(of list(of string)) in data
for i as integer = 0 to l.count
sb.Append(l(i).Padright(columns(i)))
sb.Append(" ") ' space between columns
next
sb.Append(Environment.NewLine)
next
Now you have the sb
object with the data. What you need now is to display it using some font in which each character takes up same width, for example Courier New
Warning: code typed from memory and nit checked but should represent what you're looking for