2015-10-14 63 views
-1

我有一个任务来完成..我必须从数据库填充列表视图和明智地显示和按钮单击显示它在行明智。 ..我刚刚完成从数据库填充列表视图。现在如何显示它,它逐列和行明智......请帮我... 这是我试图填充数据库的代码...显示列表视图列明智和按钮点击显示相同的列表视图在rowwise

public partial class DtposMDIParentSystem : Form 
{ 
    List<object[]> result = new List<object[]>(); 

    public DtposMDIParentSystem() 
    { 
     InitializeComponent(); 

     //create the database connection 
     OleDbConnection aConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\AP_AE\Desktop\DTPOS_APP\DataBase\DtposDatabase.accdb;"); 

     //create the command object and store the sql query 
     OleDbCommand aCommand = new OleDbCommand("SELECT * FROM Food", aConnection); 

     try 
     { 
      aConnection.Open(); 

      //create the datareader object to connect to table 
      OleDbDataReader reader = aCommand.ExecuteReader(); 

      int i = 0; 
      while (reader.Read()) 
      { 
       result.Add(new Object[reader.FieldCount]); 
       reader.GetValues(result[i]); 
      } 
      reader.Close(); 
      aConnection.Close(); 
     } 
     catch (InvalidOperationException ex) 
     { 
      MessageBox.Show("Invalid Masseage = " + ex.Message); 
     } 

    } 

    private void cmdOlives_Click(object sender, EventArgs e) 
    { 
     if (result.Count > 0) 
      { 
       string temp = ""; 

       for (int i = 0; i < result[1].Length; i++) 
       { 
        temp += result[1][i] + "  "; 
       } 
       TableOrderListView.Items.Add(temp); 
      } 
    } 
} 
+0

你解决了你的问题吗? – TaW

回答

0

您可以实现类似的东西不同的视图模式之间进行切换:

private void checkBox1_CheckedChanged(object sender, EventArgs e) 
{ 
    if (checkBox1.Checked) 
    { 
     listView1.View = View.Details; 
     listView1.HeaderStyle = ColumnHeaderStyle.None; 

     listView1.Columns[0].Width = listView1.ClientSize.Width - 25; 
     listView1.Height = 244; 
    } 
    else 
    { 
     listView1.View = View.List; 

     listView1.Columns[0].Width = 50; 
     listView1.Height = 44; 
    } 
} 

您需要添加一个ColumnDetails视图的工作!

请注意,你将不得不调整列表视图大小:

  • Details模式下,将需要足够高,以显示几个项目
  • List模式下,将不得不以相当宽但不得高到显示多个项目(加上滚动条)!

如果您想要切换行和列,您必须在数据源中执行该操作!