Solved

Using a list as a datasource

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

760 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

21 Experts available now in Live!

Get 1:1 Help Now