Solved

Using a list as a datasource

Posted on 2007-11-14
3
1,026 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 500 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 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