For example, I have a record of quizzes. I want to display all of the quizzes along with the student who took it. If the total number of quizzes is 20, then the list-view would dynamically add another column to the list-view. How can I do that? Also, I want the 1st column of the list-view to display the name of the students.
This is how I manually add the items to the column.
listView1.Items.Clear();
conek.OPEN("Select * from thesisdb.teachers where username='"+txts+"'");
while(conek.reader.Read()){
ListViewItem ni = new ListViewItem(conek.reader[0].ToString());
ni.SubItems.Add(conek.reader[1].ToString());
ni.SubItems.Add(conek.reader[2].ToString());
ni.SubItems.Add(conek.reader[3].ToString());
ni.SubItems.Add(conek.reader[4].ToString());
ni.SubItems.Add(conek.reader[5].ToString());
ni.SubItems.Add(conek.reader[6].ToString());
ni.SubItems.Add(conek.reader[7].ToString());
ni.SubItems.Add(conek.reader[8].ToString());
ni.SubItems.Add(conek.reader[9].ToString());
listView1.Items.AddRange(new ListViewItem[] { ni });
}
conek.CLOSE();
I tried using a for loop for the number of items for the reader but it doesn't seem to be working.
this class was given by our instructor and this is what we have been using ever since we started in c#.
namespace spms.classes
{
public class clsOpenCon
{
public static string connectionAddress = "uid=root; database=thesisdb;";
public static MySqlConnection CN = new MySqlConnection(classes.clsOpenCon.connectionAddress);
public MySqlCommand Com = new MySqlCommand();
public MySqlDataReader reader;
public void nonQuery(string cmdText)
{
Com.Connection = CN;
CN.Open();
Com.CommandText = cmdText;
Com.ExecuteNonQuery();
Com.Dispose();
CN.Close();
}
public void OPEN(string cmdtext)
{
Com.Connection = classes.clsOpenCon.CN;
classes.clsOpenCon.CN.Open();
Com.CommandText = cmdtext;
reader = Com.ExecuteReader();
}
public void CLOSE()
{
reader.Close();
Com.Dispose();
classes.clsOpenCon.CN.Close();
}
}
}