How can I populate objectListView's cells with SQL Server data?
You can use a DataListView, inherited from ObjectListView
I have no SQL Server to test, but I did a test with an Access database
You can adapt it by changing the connexion string
// using System.Data.OleDb; string sFile = "E:\\Employees.accdb"; string sSql = "SELECT FirstName, LastName, Location FROM employees"; //string sSql = "SELECT * FROM employees"; OleDbCommand myCommand = new OleDbCommand(); OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + sFile + ";Persist Security Info=False;Jet OLEDB:Database Password='toto';"); OleDbDataAdapter dataadapter = new OleDbDataAdapter(sSql, myConnection); DataSet ds = new DataSet(); myConnection.Open(); dataadapter.Fill(ds, "employees_table"); myConnection.Close(); dataListView1.DataSource = ds; dataListView1.DataMember = "employees_table"; dataListView1.AutoResizeColumns(); dataListView1.ShowGroups = false;
Thanks for your reply.
I have tried it. However the red lines moves to Student_dataListView. I wonder if this is not the true dataListView.
At a time, when I draw a dataListView, it appears grey in the middle. There are 2 extra links when I click at the top-right triangle. I redraw many times but it can't be reproduced.
7 people are following this question.