hello, ik would like to use a jagged array to send data that was filled in a listview
this data i get from a database
my code so far is
public static object[][] zoekiets(string sql)
{
int rij;
int col;
SqlDB Zeilen = new SqlDB();
Zeilen.fillDataset("tblZoekiets", sql, true);
int aantal_columns = Zeilen.DS.Tables["tblZoekiets"].Columns.Count;
int aantal_rows = Zeilen.DS.Tables["tblZoekiets"].Rows.Count;
object[][] zoeklijst = new object[1][];
rij = 0;
foreach (DataRow dr in Zeilen.DS.Tables["tblZoekiets"].Rows)
{
for (int teller = 0; teller < aantal_columns; teller++)
{
zoeklijst[rij][teller] = new Type(dr[teller].GetType); !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
rij++;
}
the thing is that the type of data is always different depending on the sql that comes with it
where i put the !!!!!!!!!!!!! it goes wrong
i have to declare the type for every column but how do i do that
wim de moorPosted Mar 5, 2008, 11:43 AM
my problem was to know the data type of something that is in the array
but i solved it by putting everything as object in the array
where i call for it, i know what is on which spot, so i can cast it to the right type there
here is part of my code
private object[][] lvAlleVakken_vul;
private void lvVakkenInCursus_vullen()
{
try
{
sql =
"select vak_naam, vak_max, vak_min, vak_ndx, vak_curs_pl_ndx, vak_aktief ";sql +=
"from tblVakken ";sql +=
"where vak_brevet_ndx = " + brevet_ndx + " and vak_aktief = 'true' and vak_curs_pl_ndx = 0;";lvVakInCurs_vul =
Globals.populate_listview(sql, lvVakkenInCursus, 3); if (lvVakkenInCursus.Height > 320) lvVakkenInCursus.Height = 320;}
catch { }}
private void lvAllevakken_SelectedIndexChanged(object sender, EventArgs e){
try{
selected_ndx =
Convert.ToInt16(lvAllevakken.SelectedIndices[0]);}
catch { }}
public static object[][] populate_listview(string sql, ListView lvnaam, int tonen)
{
//tonen is voor het aantal columns die in de lv getoond moeten worden
//dit zijn de eerste velden uit de sql
int rij;
int col;
SqlDB Zeilen = new SqlDB();
lvnaam.Items.Clear();
Zeilen.fillDataset("tblLijst", sql, true);
int aantal_columns = Zeilen.DS.Tables["tblLijst"].Columns.Count;
int aantal_rows = Zeilen.DS.Tables["tblLijst"].Rows.Count;
object[][] lvlijst = new object[aantal_rows][];
rij = 0;
foreach (DataRow dr in Zeilen.DS.Tables["tblLijst"].Rows)
{
lvlijst[rij] = new object[aantal_columns];
rij++;
}
try
{
lvnaam.Height = 30;
rij = 0;
//foreach (DataRow dr in Zeilen.DS.Tables["tblLijst"].Rows)
for (int teller = 0; teller < aantal_rows; teller++)
{
col = 0;
lvnaam.Height += 17;
foreach (DataColumn dc in Zeilen.DS.Tables["tblLijst"].Columns)
{
if (col == 0)
{
lvnaam.Items.Add(Zeilen.DS.Tables["tblLijst"].Rows[rij][0].ToString());
}
else
{
if (col < tonen)
{
lvnaam.Items[rij].SubItems.Add(Zeilen.DS.Tables["tblLijst"].Rows[rij][col].ToString());
}
}
lvlijst[rij][col] = Zeilen.DS.Tables["tblLijst"].Rows[rij][col];
col++;
}
rij++;
}
lvnaam.Visible = true;
lvnaam.GridLines = true;
lvnaam.View = View.Details;
}
catch (Exception ex)
{ MessageBox.Show("fout : " + ex.Message); }
{ return lvlijst; }
}
Shanmughapriya MPosted Mar 5, 2008, 7:44 AM
Could you be more clear about your question for information on jagged arrays
http://msdn2.microsoft.com/en-us/library/2s05feca.aspx
http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingWithArrays11232005064036AM/WorkingWithArrays.aspx