Affichage des articles dont le libellé est Multidimensional Array. Afficher tous les articles
Affichage des articles dont le libellé est Multidimensional Array. Afficher tous les articles

Javascript Display Multidimensional Array Content

How To Show 2D Array Data Using Javascript 

Display 2D Array Data In JS


In This Javascript Tutorial we will See How To Display A Multi-Dimensional Array Data Using For Loop In JS And Netbeans Editor .


Project Source Code:

    
<!DOCTYPE html>
<html>
    <head>
        <title>Javascript: display 2D array content</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>

        <script>
            
            var ar = [
                       ["A1","B1","C1","D1"],
                       ["A2","B2","C2","D2"],
                       ["A3","B3","C3","D3"],
                       ["A4","B4","C4","D4"],
                       ["A5","B5","C5","D5"]
            ], txt = "";
            
            for(var i = 0; i < ar.length; i++){// lines
        
                   for(var k = 0; k < ar[i].length; k++){// columns
                    
                    txt = txt + ar[i][k]+ " | ";
                    
                 }
              txt = txt + "<br>";
            }
            
            document.write(txt);
            
        </script>
        
    </body>
</html>



OUTPUT:



Display Multidimensional Array Content Using Javascript

VB.Net Search In A Multidimensional Array

How To Find Item Position In A 2D Array Using VB.Net

vb.net search in 2d array



In this VB.NET Tutorial we will see How To Search And Find A Value Position Inside A Multidimensional Array Using For Loop To Go through all Array Items And a TextBox To Enter The Value You want to search And Display The Positions Inside A RichTextBox On A Button Click Event In Visual Basic.Net Programming Language And Visual  Studio Editor.




Project Source Code:


Public Class _2D_Array_Create_Search_Display

   ' create 2d array
    Dim data(,) As String

    Private Sub _2D_Array_Create_Search_Display_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        ' add data to the 2d array

        data = New String(,) {
                               {"1", "A", "B", "CD"}, {"2", "C", "D", "EF"},
                               {"3", "E", "F", "KL"}, {"4", "K", "L", "MN"},
                               {"5", "M", "N", "MN"}, {"6", "G", "R", "HS"},
                               {"7", "H", "S", "ZW"}, {"8", "Z", "W", "MN"}
                             }

        ' display 2d array data
        For i As Integer = 0 To data.GetLength(0) - 1 Step +1

            For j As Integer = 0 To data.GetLength(1) - 1 Step +1

                RichTextBox1.Text += data(i, j) + " - "

            Next j

            RichTextBox1.Text += vbNewLine

        Next i


    End Sub

' button search
    Private Sub ButtonSearch_Click(sender As Object, e As EventArgs) Handles ButtonSearch.Click

' clear the RichTextBox
        RichTextBox2.Text = ""

        ' search item position in 2D array data
        For i As Integer = 0 To data.GetLength(0) - 1 Step +1

            For j As Integer = 0 To data.GetLength(1) - 1 Step +1

                If TextBox1.Text.Equals(data(i, j)) Then

                    RichTextBox2.Text += "POSITION [ " + i.ToString() + " , " + j.ToString() + " ]"
                    RichTextBox2.Text += vbNewLine

                End If


            Next j


        Next i

    End Sub
End Class


OutPut:

get item position in 2d array using vb.net




Java Populate JTable From Multidimensional Array

How To Fill A JTable With Multidimensional Array Data Using Java NetBeans

Fill JTable From Multidimensional Array Using Java



In this Java Tutorial we will see How To Populate A JTable From A 2D Array Values Using For Loop In Java NetBeans .




Project Source Code:


public void _2DArrayToTable()
    {
    
        String[][] data = {
                             {"A1","B1","C1","D1"},
                             {"A2","B2","C2","D2"},
                             {"A3","B3","C3","D3"},
                             {"A4","B4","C4","D4"},
                             {"A5","B5","C5","D5"},
                             {"A6","B6","C6","D6"},
                             {"A7","B7","C7","D7"},
                             {"A8","B8","C8","D8"},
                             {"A9","B9","C9","D9"},
                             {"A10","B10","C10","D10"} 
                          };
        
        DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
        
//        for(int i = 0; i < data.length; i++)
//        {
//            String[] row = new String[data[i].length];
//            
//            for(int j = 0; j < data[i].length; j++)
//            {
//                row[j] = data[i][j];
//            }
//            
//            model.addRow(row);
//        }
        
         for(String[] row : data){
             model.addRow(row);
         }
        
    } 


OutPut:

Populate JTable Using 2D Array In Java




Java Search In A Multidimensional Array

How To Search Value In A 2D Array Using Java NetBeans

Search Data In A Multidimensional Array Using Java



In this Java Tutorial we will see How To Search And Find A Value Position Inside A  Multidimensional Array Using For Loop And Display The Position Into A JTextArea On A JButton Click Event In Java NetBeans .




Project Source Code:


 // the array
        String[][] data = {
                             {"A1","B1","C1","D1","E","F","G"},
                             {"A2","B2","C2","D2","E","B1","G"},
                             {"A3","B3","C3","B1","E","F","G"},
                             {"A4","B4","B1","D4"},
                             {"A5","B5","C5","D5"},
                             {"A6","B6","C6","B1"},
                             {"B1","B7","C7","D7"},
                          };
    
        // show array data in textArea
    public void showArrayData()
    {
        String txt = "";
        for(int i = 0; i < data.length; i++){
            for(int c = 0; c < data[i].length; c++){
                //jTextArea1.setText(jTextArea1.getText() + "");
                txt = txt + data[i][c] + " , ";
            }
            txt = txt + "\n";
        }
        
        jTextAreaData.setText(txt);
    } 


// get positions
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                      

        String pos = "", valToSearch = jTextField1.getText();
        
        for(int i = 0; i < data.length; i++){
            for(int j = 0; j < data[i].length; j++)
            {
                if(data[i][j].equals(valToSearch)){
                    pos = pos + "POSITION [ "+i+" , "+j+" ]";
                    pos = pos + "\n";
                }
            }
            
        }
        jTextAreaPos.setText(pos);
    }


OutPut:

Get Value Position Inside A 2D Array Using Java




C# Populate DataGridView Using Multidimensional Array

How To Fill DataGridView From 2D Array Data Using C#

Fill DataGridView From Multidimensional Array Content Using C#


In This C# Tutorial  We Will See How To Populate A DataGridView From A Multidimensional Array Content Using For Loop In CSharp Programming Language And Visual  Studio Editor.


Project Source Code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class _2DArray_To_DataGridView : Form
    {
        public _2DArray_To_DataGridView()
        {
            InitializeComponent();
        }

        private void _2DArray_To_DataGridView_Load(object sender, EventArgs e)
        {
            string[,] rows = new string[,]{ // 1   2     3     4 
                                             {"1","AAA","BBB","10"},//1
                                             {"2","CCC","DDD","20"},//2
                                             {"3","ZZZ","YYY","30"},//3
                                             {"4","LLL","MMM","40"},
                                             {"5","NNN","TTT","50"},
                                             {"6","WWW","RRR","60"},
                                             {"7","GGG","PPP","70"}//7
                                          };

            // rows.GetLength(0) return length of the first D (7)
            // rows.GetLength(1) return length of the second D
            for(int i = 0; i < rows.GetLength(0); i++)// array rows
            {
                string[] row = new string[rows.GetLength(1)];

                for(int j = 0; j < rows.GetLength(1); j++)
                {
                    row[j] = rows[i, j];
                }

                dataGridView1.Rows.Add(row);
            }
        }
    }
}


// OUTPUT :

2D array to datagridview in c#



C# Search In A Multidimensional Array

How To Find Value In A 2D Array Using C#

Find Value Position In A Multidimensional Array Using C#



In this C# Tutorial we will see How To Search And Find A Value Position Inside A  Multidimensional Array Using For Loop + TextBox And Display The Positions Inside A RichTextBox On A Button Click Event In CSharp Programming Language And Visual  Studio Editor.




Project Source Code:


 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Search_In_2D_Array : Form
    {
        public Search_In_2D_Array()
        {
            InitializeComponent();
        }

        // create 2D array
        string[,] data;
        private void Search_In_2D_Array_Load(object sender, EventArgs e)
        {
            // add data to the array
            data = new string[,]{// 1    2     3    4
                                  {"1","AAA","BBB","10"},//1
                                  {"2","CCC","DDD","20"},//2
                                  {"3","ZZZ","YYY","30"},//3
                                  {"4","LLL","CCC","40"},
                                  {"5","NNN","TTT","50"},
                                  {"6","CCC","RRR","CCC"},
                                  {"7","GGG","CCC","70"}//7
                                };

            // display array data into richTextbox
            for (int i = 0; i < data.GetLength(0); i++)
            {
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    richTextBox1.Text += data[i, j] + " - ";
                }

                richTextBox1.Text += "\n";
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox2.Text = "";
            // data.GetLength(0) = length of the first D (7)
            for(int i = 0; i < data.GetLength(0); i++)
            {
                // data.GetLength(1) = length of the second D (4)
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    if(textBox1.Text.Equals(data[i,j]))
                    {
                        richTextBox2.Text += "POSITION[" + i + " , " + j + "]";
                    }
                }
            }

        }

        
    }
}


OutPut:

search in 2D array using c#