home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

using listboxes in C#

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2193
Discussions: 200,945, Posts: 2,379,351, Members: 246,307
Old July 27th, 2006, 01:28 PM   Digg it!   #1 (permalink)
Mobile Member
 
ShuckyD's Avatar
 
Join Date: Apr 2005
Location: S. Central PA
Posts: 3,601
using listboxes in C#

I have an application that i have been working on which is done with C# as well as being a smart device so i am using the compact framework. Some things are done differently in there, i have found out the hard way, but this should be fine im just not sure how i would go about getting this to work.

In the application we have someone scan a barcode, that barcode generates a list of items to get. (Right now i have that all done in a textbox) The SQL statement that pulls the whole list looks like this

Code:
public string PullMyOrder(string Order)
		{
			try
			{
				Connect();
				System.Data.SqlClient.SqlDataReader reader;
				rs.CommandText="SELECT [Sales Order Pickticket].[Line Number], " +
					"[Sales Order Pickticket].[Item Number], [Sales Order Pickticket].[BO Qty]-CONVERT(MONEY,dbo.fnc_nz(CONVERT(nvarchar(50),[PickedQty]),0)), " +
					"LEFT([Description],12) FROM [Sales Order Lineitems] INNER JOIN [Sales Order Pickticket] ON " +
					"([Sales Order Lineitems].[Sales Order Number]=[Sales Order Pickticket].[Sales Order Number]) AND " +
					"([Sales Order Lineitems].[Line Number]=[Sales Order Pickticket].[Line Number]) " +
					"WHERE [Sales Order Pickticket].[Sales Order Number]='" + Order + 
					"' AND ([Sales Order Pickticket].[BO Qty]-CONVERT(MONEY,dbo.fnc_nz(CONVERT(nvarchar(50),[PickedQty]),0))) > 0 AND [Shipped]=0";

				reader=rs.ExecuteReader();
				Order="";
				while (reader.Read() == true)
				{
					if (Order != "")
					{
						Order = Order + "\r\n";
					}
					strOrder = strOrder + reader.GetInt32(0).ToString().PadRight(4) + 
						reader.GetString(1)+ "\t" + reader.GetSqlMoney(2).ToString().PadRight(6) 
						+ reader.GetString(3);
				}
				reader.Close();
			}
			catch (SqlException ex)
			{
				MessageBox.Show(ex.Message,"XYZ: " + ex.Number);
			}
			Disconnect();
			return Order;
		}
that pulls the whole order and plops it right into that textbox. I need more control over that so i have to change it to a list box so that we just display the item that is suspose to be picked and then the item after, or something similar. I cant really do that with a text box since its all one large thing with new lines at the end of the item.

I want to be able to make the application tell the person using it via SQL coding where the location is for the next item, i have those textboxes already added to the form now all i have to do is get this working so i have an area to read from and then find their location. Follow?

So what im pretty much asking is how do you use a list box to do what i am trying to do. Ive seen how to add items to the collection, but you have to do that manually, i want to add things via code, and then be able to target specific things lines in there
__________________
Thinkpad T61 14.1" wide | WinXP Pro | C2D T8300 CPU | 3GB DDR2 | 160GB HDD | AGN & WWAN
Lenovo S10 10.2" LED display | 1.6Ghz Atom CPU | 1GB DDR2 | 1.3mp webcam | B/G WiFi | 160GB HDD
ShuckyD is offline   Reply With Quote
Old July 28th, 2006, 10:39 AM     #2 (permalink)
Banned
 
Iturea's Avatar
 
Join Date: Jan 2004
Location: Earth
Posts: 420
Quote:
Originally Posted by ShuckyD
that pulls the whole order and plops it right into that textbox. I need more control over that so i have to change it to a list box so that we just display the item that is suspose to be picked and then the item after, or something similar. I cant really do that with a text box since its all one large thing with new lines at the end of the item.

I want to be able to make the application tell the person using it via SQL coding where the location is for the next item, i have those textboxes already added to the form now all i have to do is get this working so i have an area to read from and then find their location. Follow?

So what im pretty much asking is how do you use a list box to do what i am trying to do. Ive seen how to add items to the collection, but you have to do that manually, i want to add things via code, and then be able to target specific things lines in there

Well I don't understand fully what you are looking for but I am going to take a stab in the dark and say create an ArrayList? -- So you can access the items you want such as the next item in the list...

Code:
// Somewhere in your function or class create object
ArrayList lstItems = new ArrayList();

while (reader.Read())
{
  if (Order != "")
  {
    Order = Order + "\r\n";
  }
  
  //WHERE lstItems IS YOUR NEW ARRAYLIST
  lstItems.Add(reader["listitemsfield"].ToString());

  
  strOrder = strOrder + reader.GetInt32(0).ToString().PadRight(4) + 
  reader.GetString(1)+ "\t" + reader.GetSqlMoney(2).ToString().PadRight(6) 
  + reader.GetString(3);
}
Then just pull the items you want out of the lstItems Array programmatically...

I know that's not your SQL example, but couldn't that work?

Last edited by Iturea : July 28th, 2006 at 10:44 AM.
Iturea is offline   Reply With Quote
Old July 28th, 2006, 12:36 PM     #3 (permalink)
Mobile Member
 
ShuckyD's Avatar
 
Join Date: Apr 2005
Location: S. Central PA
Posts: 3,601
i think it can, let mne giveit a try
ShuckyD is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Making Health Care Worse (164)
The disrespect of Obama by Russian .. (17)
Is It Just Me? (2921)
Wireless Televisions. (11)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Regular Build (6)
Is the PSU I received dead? (12)
Print spooler problem (15)
HIS HD5770 graphic card question (15)
windows vista security holes (9)
Install XP pro and a Vista laptop ?.. (11)
Foreign voltage (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
Recent Discussions
Is the PSU I received dead? (12)
How to convert MP3's (2)
windows 7 internet problem (5)
Multiple Restarts Required at Boot (0)
BSOD On Startup (ntoskrnl.exe) (2)
Print spooler problem (15)
Laptop with wireless problem. (1)
Wireless Televisions. (11)
Have you switched yet? (86)
Asus P4G8X Mobo (5)
screen resolution vs monitor size (2)
radeon x850xt platinum & shader 3 (4)
sms storage to PC (0)
Regular Build (6)
Open With ..... Win7 (0)
java code for fibonacci (1)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (35)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Partition Magic caused HDD problem (3)
Point and Shoot Camera Suggestions. (2)
Modern Warfare 2 freeze (13)
wireless user (1)
World's largest Monopoly Game using G.. (332)
Ideal cheap graph card for PC-Gaming? (17)


All times are GMT -4. The time now is 06:42 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28