- Home /
how to create array with grid layout group
i want to create matrix 4 x n with List<> how to create array for it? and i have 4 strings into List. please help me :'(
Can you explain in more detail. I am a little confused on what you are trying to do.
Can you clarify your problem? Are you showing the strings on your grid UI and need to store them somewhere?
Answer by OneCept-Games · Jan 08, 2018 at 04:51 PM
Lists can contain a struct, so create a struct with 4 equal objects, and use the struct in the List type.
if its integer/ double, i want to calculate the value into grid. I have this in c# VS:
bool flag = true;
double tmp;
for (int i = 1; (i < Listbuilding.RowCount-1) && flag; i++)
{
flag = false;
for (int j = 0; j < Listbuidling.RowCount-1; j++)
{
if (_saw[0, j + 1] > _saw[0, j])
{
tmp = _saw[0, j];
_saw[0, j] = _saw[0, j + 1];
_saw[0, j + 1] = tmp;
tmp = _saw[1, j];
_saw[1, j] = _saw[1, j + 1];
_saw[1, j + 1] = tmp;
flag = true;
}
}
}
how its in unity? *sorry I'm still newbie
Your code seem to be C already, so not much difference in Unity Script/C#.
Your Listbuidling i assume is an Array, so RowCount would be Length ins$$anonymous$$d.
_saw in your case would just be Listbuidling[], unless you try to transfer Listbudling to _saw, where you could just use Array.Clone().
If you want to cast doubles to integers you just use the cast syntax, like: tmp = (double)_saw[];
Hope it brings you further, but i need more context, if you need more detailed answer.
I want to create Simple Additive Weighting (SAW) method, and this is my code :
private DB _dbctrl = new DB();
private List<ListBuilding> Listbuilding = new List<ListBuilding>();
public double[] _Capacity, _Rooms, _Equipment, _Parking;
public double[,] _saw;
void normalization()
{
int row = Listbuilding.RowCount;
_Capacity = new double[row];
_Rooms = new double[row];
_Equipment = new double[row];
_Parking = new double[row];
double maxCapacity =0, maxRooms = 0, maxEquipment = 0, maxParking = 0;
// i want to get data from sqlite
for (int i=0; i<row;i++)
{
_Capacity[i] = (double)Listbuilding.Rows[i].Cells["CAPACITY"].Value;
_Rooms[i] = (double)Listbuilding.Rows[i].Cells["ROO$$anonymous$$S"].Value;
_Equipment[i] = (double)Listbuilding.Rows[i].Cells["EQUIP$$anonymous$$ENT"].Value;
_Parking[i] = (double)Listbuilding.Rows[i].Cells["PAR$$anonymous$$ING"].Value;
if(i==0)
{
maxCapacity = _Capacity[i];
maxRooms = _Rooms[i];
maxEquipment = _Equipment[i];
maxParking = _Parking[i];
}
else
{
if (maxCapacity < _Capacity[i])
maxCapacity = _Capacity[i];
if (maxRooms < _Rooms[i])
maxRooms = _Rooms[i];
if (maxEquipment < _Equipment[i])
maxEquipment = _Equipment[i];
if (maxParking < _Parking[i])
maxParking = _Parking[i];
}
}
for (int i = 0; i < row; i++)
{
_Capacity[i] /= maxCapacity;
_Rooms[i] /= maxRooms;
_Equipment[i] /= maxEquipment;
_Parking[i] /= maxParking;
}
}
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.Columns.Clear();
normalization();
_saw = new double[2,Listbuilding.RowCount];
double w_capacity, w_rooms, w_equipment, w_parking;
w_capacity = double.Parse(valcapacity.Text);
w_rooms = double.Parse(valrooms.Text);
w_equipment = double.Parse(valequipment.Text);
w_parking= double.Parse(valparking.Text);
double sumWeight = w_parking + w_rooms + w_capacity + w_equipment;
// initialization weights
if (w_capacity== 0)
w_capacity = 0.001;
else
w_capacity /= sumWeight;
if (w_rooms == 0)
w_rooms = 0.001;
else
w_rooms /= sumWeight;
if (w_equipment == 0)
w_equipment = 0.001;
else
w_equipment /= sumWeight;
if (w_parking == 0)
w_parking = 0.001;
else
w_parking /= sumWeight;
// saw method
for (int i = 0; i < Listbuilding.RowCount; i++)
{
_saw[0,i] = (_Parking[i] * w_parking) + (_Rooms[i] * w_rooms) + (_Capacity[i] * w_capacity) +(_Equipment[i] * w_equipment);
_saw[1, i] = i;
//dataGridView1.ColumnCount = 2;
//dataGridView1.Rows.Add(_saw[1,i], _saw[0,i]);
}
bool flag = true;
double tmp;
for (int i = 1; (i < Listbuilding.RowCount-1) && flag; i++)
{
flag = false;
for (int j = 0; j < Listbuilding.RowCount-1; j++)
{
if (_saw[0, j + 1] > _saw[0, j])
{
tmp = _saw[0, j];
_saw[0, j] = _saw[0, j + 1];
_saw[0, j + 1] = tmp;
tmp = _saw[1, j];
_saw[1, j] = _saw[1, j + 1];
_saw[1, j + 1] = tmp;
flag = true;
}
}
}
double column1,column2,column3,column4;
for (int i = 0; i < 5; i++)
{
int index = (int)_saw[1,i];
dataGridView1.ColumnCount = 4;
dataGridView1.Columns[0].HeaderText = "CAPACITY";
dataGridView1.Columns[1].HeaderText = "ROO$$anonymous$$S";
dataGridView1.Columns[2].HeaderText = "EQUIP$$anonymous$$ENT";
dataGridView1.Columns[3].HeaderText = "PAR$$anonymous$$ING";
column1 = (double)Listbuilding.Rows[indeks].Cells["CAPACITY"].Value;
column2 = (double)Listbuilding.Rows[indeks].Cells["ROO$$anonymous$$S"].Value;
column3 = (double)Listbuilding.Rows[indeks].Cells["EQUIP$$anonymous$$ENT"].Value;
column4 = (double)Listbuilding.Rows[indeks].Cells["PAR$$anonymous$$ING"].Value;
dataGridView1.Rows.Add(column1,column2,column3,column4);
//dataGridView1.ColumnCount = 2;
//dataGridView1.Rows.Add(_saw[1,i], _saw[0,i]);
}
}
I use datagridview for my list data, but I wanna use grid layout group in unity and get the data from sqlite. but I don't know to do it :( very grateful if you can help me, friend. thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220612150057im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Javascript array questions. 1 Answer
Recursive Tree Loop? How do i make the matrix-array? 3 Answers
As I compare 4 objects in an array? 2 Answers
IndexOutOfRangeException: Array index is out of range. 1 Answer
How destroy a object and it's similars 4 Answers