Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using a list as a datasource

Posted on 2007-11-14
3
Medium Priority
?
1,028 Views
Last Modified: 2013-12-17
I have some classes set up that will extract a row of data from a sql table:

List<Action> List1 = Bal.Action_SelectList(2, null);
There are 3 columns in this table, and therefore there are 3 items that are added to this list.

Is it possible to use this list as a datasource for two comboboxes and a textbox?
0
Comment
Question by:tiehaze
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 20285149
So you have a Action class. To make this possible to be binded you must have the 3 desired columns represented inside the class as 3 public properties with both Get and Set. Only Get (read-only properties) will also do but will set a read-only grid.

It's very important that they are properties, simple variables won't do.


If you have the List<Action> being Action a class written as I described above you simply need to set List1 as the grid datasource and let the grid generate its own columns or desable the AutoGenerateColumns property and add your own columns mapping them to the property names on the class.
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 20285160
I'm sorry, I was talking about a grid and you never mentioned one.
Everything applies to combo's and TextBoxes except TextBox's don't have DataSource, you must use databindings.
0
 
LVL 1

Accepted Solution

by:
adam_ingeniti earned 2000 total points
ID: 20285674
What AlexCode is describing is basically creating an object (ie. class) representation of your data - in code. So, for instance, if this is a "person" we're talking about data for, you might create a class called Person to represent that data in a more meaningful way in your application...

You'll notice that I have included two constructors in the class - the first one is a more standard approach, while the second overload is an example of how you could create a new Person from your existing data call (ie. the one which returns a List<Action>).

Not sure if this is the way you were thinking to start with... although this is a recognised good practice / approach. Perhaps you could describe the data in your db table in more detail? It's a bit hard to give a really useful answer without a better understanding of what you're trying to achieve.
	public class Person
	{
		private string _name;
		private int _personID;
		private string _address;
 
		public int PersonID
		{
			get { return _personID; }
			set { _personID = value; }
		}
 
		public string Name
		{
			get { return _name; }
			set { _name = value; }
		}		
 
		public string Address
		{
			get { return _address; }
			set { _address = value; }
		}
 
 
		
		public Person(int dbPersonID, string dbName, string dbAddress)
		{
			this._personID = dbPersonID;
			this._name = dbName;
			this._address = dbAddress;	
		}
 
		public Person(List<Action> ActionList) : this(ActionList[0], ActionList[1], ActionList[2])
		{ } 
	}

Open in new window

0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question