Solved

Using a list as a datasource

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

615 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