Solved

Using a list as a datasource

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now