views:

18

answers:

3

I've never personally used any of the Data controls within Visual Studio. I need to view and edit a two-dimensional byte array, 16x15 objects. Is there any control capable of editing this information?

I've tried to access data with the DataViewGrid, but am not sure how to use it.

It would be great to edit this information via rows and columns, like how you can in Excel.

Thank you!


Times like this I wish I could just use multiple text boxes and assign them each an index value. Oh VB6 how I miss you :P

A: 

After only 20 more minutes of searching (and changing my search terms) I found a nifty solution (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

Credit goes to: http://www.velocityreviews.com/forums/t106436-binding-multidimensional-array-to-datagrid.html

Jeffrey Kern
A: 

Following is part of my Array debug visualizer (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);
AMissico
Thank you. I never thought about having to disable sorting. :)
Jeffrey Kern
+1  A: 

"Times like this I wish I could just use multiple text boxes and assign them each an index value. Oh VB6 how I miss you."

Create a list of text-boxes and just add each TextBox control to the list. You can even store the index of the text-box into its Tag property.

   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

(I miss nothing of VB. The .NET Framework and VB.NET are awesome.)

AMissico