문제

I try to create my own SQL QUERY Analyzer. It works perfectly with a datagridview.

But I try to add a version that offers the text mode version. And I want this text mode having data in columns, to have a clean view.

This code that I try is working to put data in a textbox in columns, but it's VERY SLOW!!! (Other thing, the data seems not to be align in column, but If I copy to contains of the textbox in Notepad, it looks great).

For increm = 0 To DataGridSQLQuery.RowCount - 2
    For inc = 0 To DataGridSQLQuery.ColumnCount - 1
        str = ""
        str = str.PadRight(DataGridSQLQuery.Columns(inc).Width - DataGridSQLQuery.Rows(increm).Cells(inc).Value.ToString.Length, padvide)
        txtMessageErreur.Text = txtMessageErreur.Text + DataGridSQLQuery.Rows(increm).Cells(inc).Value.ToString + str + " "
    Next
     txtMessageErreur.Text = txtMessageErreur.Text & Environment.NewLine
 Next

Is there's a way to link data to create the text mode version in a second. Can I use another tool than a textbox Maybe ?

thanks for your help

도움이 되었습니까?

해결책

Strings are immutable, so str has to be recreated over and over. If there are a lot of rows or columns, use a stringbuilder:

Dim sb As New StringBuilder

For r As Integer = 0 To DataGridSQLQuery.RowCount - 2
    For c = 0 To DataGridSQLQuery.ColumnCount - 1
        sb.Append( your text to add to the string )

        sb.Append(Environment.NewLine)
        txtMessageErreur.Text = sb.Tostring

        sb.Clear      ' reset for next iteration
    Next c
Next r

The text will not line up in a textbox or listbox like columns, unless you use a monospace font. W takes more room than i. PadLeft/Right will help but not a lot

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top