可视化查看和编辑二维数组 - VB / C#

时间:2010-06-12 10:22:25

标签: .net arrays data-binding

我从未亲自使用Visual Studio中的任何数据控件。我需要查看和编辑一个二维字节数组,16x15对象。有没有能够编辑这些信息的控件?

我尝试使用DataViewGrid访问数据,但我不确定如何使用它。

通过行和列编辑此信息会很棒,就像在Excel中一样。

谢谢!


这样的时间我希望我可以使用多个文本框并为每个文本框分配一个索引值。哦VB6我多么想念你:P

3 个答案:

答案 0 :(得分:1)

经过20多分钟的搜索(并更改我的搜索条件)后,我找到了一个漂亮的解决方案(VB.NET)

Public Class Form1
    Dim data As New DataTable

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer

        For i = 0 To 15
            data.Columns.Add(New DataColumn("X" & i, GetType(Byte)))
        Next i

        For i = 0 To 14
            Dim dr = data.NewRow()
            data.Rows.Add(dr)
        Next

        DataGridView1.DataSource = data

    End Sub
End Class

信用证转到:http://www.velocityreviews.com/forums/t106436-binding-multidimensional-array-to-datagrid.html

答案 1 :(得分:1)

  

“这样的时间,我希望我可以   使用多个文本框并分配   它们每个都是一个索引值。哦VB6我怎么样   想念你。“

创建一个文本框列表,只需将每个TextBox控件添加到列表中。您甚至可以将文本框的索引存储到其Tag属性中。

   Public Class Form1

    Private _textBoxes As New List(Of TextBox)

    Public Sub New()
        InitializeComponent()
        _textBoxes.Add(TextBox1)
        _textBoxes.Add(TextBox2)
        _textBoxes.Add(TextBox3)
        For Each oTextBox As TextBox In _textBoxes
            AddHandler oTextBox.Enter, AddressOf TextBox_Enter
            AddHandler oTextBox.Leave, AddressOf TextBox_Leave
            oTextBox.Tag = _textBoxes.IndexOf(oTextBox)
        Next
        For Each oTextBox As TextBox In _textBoxes
            Debug.WriteLine(CInt(oTextBox.Tag), "Index of " + oTextBox.Name)
        Next
    End Sub

    Private Sub TextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim iIndex As Integer = _textBoxes.IndexOf(CType(sender, TextBox))
        Debug.WriteLine(iIndex, "IndexOf")
        Debug.WriteLine(DirectCast(sender, TextBox).Name, "Enter")
    End Sub

    Private Sub TextBox_Leave(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim iIndex As Integer = _textBoxes.IndexOf(CType(sender, TextBox))
        Debug.WriteLine(iIndex, "IndexOf")
        Debug.WriteLine(DirectCast(sender, TextBox).Name, "Leave")
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _textBoxes(1).BackColor = Color.Tomato
    End Sub

End Class

(我对VB不感兴趣..NET Framework和VB.NET非常棒。)

答案 2 :(得分:0)

以下是我的Array调试可视化工具(ftp://missico.net/ArrayVisualizer.zip

的一部分
        //' x is columns
        //' y is rows

        //' x is first dimension
        //' y is second dimension

        //'create data table
        DataTable oData = new DataTable("Array");

        //'handle columns
        for (int x = 0; x <= _array.GetUpperBound(0); x++) {
            oData.Columns.Add(x.ToString(), typeof(string));
        }

        //'populate data
        for (int iRow = 0; iRow <= _array.GetUpperBound(1); iRow++) {
            DataRow oRow = oData.NewRow();
            for (int iCol = 0; iCol <= _array.GetUpperBound(0); iCol++) {
                oRow[iCol] = _array.GetValue(iCol, iRow);
            }
            oData.Rows.Add(oRow);
        }
        oData.AcceptChanges();

        //'data source
        __grid.DataSource = oData;

        //'handle row index
        int j = 0;
        foreach (DataGridViewRow oRow in __grid.Rows) {
            oRow.HeaderCell.Value = j.ToString();
            j += 1;
        }

        //'disallow sorting
        foreach (DataGridViewColumn oCol in __grid.Columns) {
            oCol.SortMode = DataGridViewColumnSortMode.NotSortable;
        }

        //'resize everything
        __grid.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
        __grid.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCells);