Dear All,
How can I populate objectListView's cells with SQL Server data?
TIA
Dear All,
How can I populate objectListView's cells with SQL Server data?
TIA
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;

Hi @Castorix31
The connection string for Access is
"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + sFile + ";Persist Security Info=False;Jet OLEDB:Database Password='toto';"
Could you tell me the connection string for SQL Server 2016?
Thanks!
On the site I posted there are some connexion strings for different SQL Server versions : Microsoft OLE DB Driver for SQL Server connection strings
Hi @Castoric31,
I've followed your code and modified the connection string to make it connect to SQL Server. However the Student_dataListViews were red lined. The only difference was the connection string. May I know how to fix it?

Hi @Castorix31,
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.


If it is created with the Designer (this.Student_dataListView = new BrightIdeasSoftware.DataListView(); , etc...)
remove the static keyword in your function
6 people are following this question.
Insert a node as child ,before or after a node in nested dynamic JSON Node using C#
Visual Studio 2019: Undefined behavior in a C++/CLI wrapper project.
Example for how to get Package Metadata from Azure DevOps Rest-Api Artifacts using c#
How to collapse individual nested grids/stackpanels inside a grid?