|
private void cmdOlives_Click(object sender, EventArgs e)
{
if (menuItems.Count > 0)
{
System.Windows.Forms.ListViewItem newItem = new System.Windows.Forms.ListViewItem(menuItems[1].ToString());
for (int i = 1; i < menuItems[1].ItemName.Length; i++)
{
newItem.SubItems.Add(menuItems[i].ToString());
}
TableOrderListView.Items.Add(newItem);
}
}
|
|
|
|
|
Please say what the problem is.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I have created a working version of what I think you are trying to do. It does not use the same structures (List<> etc.) as you since I think that is not the right way to do things.
Would you like to see it?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry
I just came back from work.
If its not much to truble yes I would like to see it please
Kind regards
Roni
|
|
|
|
|
Look out for an email from hfam at live stop co stop uk.
I'll attach the zipped solution.
In it I am using SqlConnection, SqlDataAdapter etc. If you do not have SqlServer then change those to OleDbWhatevers and it should be OK.
The database structure I have used is designed for simplicity and would probably not be suitable for a 'real' environment.
There are two tables (Starter and Main) and both have the same structure.
Field: ItemID - int identity (autoincrement)
Field: ItemName - nvarchar(50)
Field: ItemPrice - Money
Give a shout if there are any problems with it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
hi Henry
what email I should look and where is this hfam at live stop co stop uk.
roni
|
|
|
|
|
My most recent message makes this unnecessary.
But for future reference, it is a bad idea to post your email address in a public forum like this one because nasty evil people have bots scouring the internet for valid email addresses so that they can use them for naughty things.
So what I typed was a way of giving an email address without actually showing what it is.
So if my Email was bum@someisp.com I would tell you it was bum at someisp stop com
Geddit?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I've just realized that my previous idea (Email) won't work, Can't add attachments in CP Email.
So I've uploaded it to AddItemsToListView.zip[^] you can download it from there.
Good luck.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry
I've downloaded the zip file. thank you ever so much..
I will have to look it up tomorow, cos its getting late here and I'm working tomorow...
But in the mean time I will let you know if im facing any problem...
Kind regards
Roni
|
|
|
|
|
Hi Henry
I have managed to sort it out the zip file that you sendit and its working very well so far,
but I'm facing a bit problem with my database...
The problem I'm facing is that on my database I have 2 tables:
Food Table - with Field Names - Food_ID(Number), Food_Name(Text), Food_Type(Text), Food_Price(Currency)
Drink Table - with Field Names - Drink_ID(Number), Drink_Name(Text), Drink_Type(Text), Drink_Price(Currency)
Now what I'm concern is that what happens when I choose a different type of Food or Drink...
Kind regards
Roni
|
|
|
|
|
I'll have a think and get back to you tomorrow.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
I have an idea that might help but it depends on what purpose your Food_Type field serves. Does it signify that something is a starter, main etc. or is it something like meat, dairy etc.?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry
Well basically the Food_Type field on the Food table represents
such as
-Starter
-Main
-Dessert
-Side Order
-Salads
-etc. etc.
|
|
|
|
|
Good!
Once again if I am correct in assuming that what you are designing will not be used for entering data into the main tables but simply for taking orders or similar functions.
You can keep the DataSet and DataTable structure I used in my example. All that needs to change are the Sql SELECT statements, like this:
string starterSql = @"SELECT * FROM Food WHERE Food_Type = 'Starter'";
string mainSql = @"SELECT * FROM Food WHERE Food_Type = 'Main'";
using (SqlConnection conn = new SqlConnection(connString))
{
try
{
conn.Open();
SqlDataAdapter starterDa = new SqlDataAdapter(starterSql, conn);
starterDa.Fill(menuDS, "Starter");
SqlDataAdapter mainDa = new SqlDataAdapter(mainSql, conn);
mainDa.Fill(menuDS, "Main");
SqlDataAdapter dessertDa = new SqlDataAdapter(dessertSql, conn);
dessertDa.Fill(menuDS, "Dessert");
starterTable = menuDS.Tables["Starter"];
mainTable = menuDS.Tables["Main"];
dessertTable = menuDS.Tables["Dessert"];
}
catch (Exception e)
{
Console.WriteLine("Error: " + e);
}
}
One thing I will say is that you should not press ahead with designing all your user controls just yet. For now just have, maybe, two for testing purposes. The reason for this is that in reality you will not know what buttons will be required until run-time and the buttons will therefore need to be created and added dynamically depending on what items are in the Food database at that time. These things change, some items are dropped and others added. So what should happen is that there should only be one UserControl exactly the same as the one in my example but without the Buttons. When needed, a new one should be created by adding the buttons and hooking them up to the ItemSelected Event.
When you are ready for that I will help you, if you need it.
Good luck.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Is it neccesary to use LIKE clouse
|
|
|
|
|
I don't think so. Try without first and only use it if there are problems.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry
I have tried that but its not working.
Now another problem is rising.
When I run my application and when I click Starters Button it does work adding items to list view (such as olives, soup, etc etc) also it works for Mains button, but HERE IS THE THING PROBLEM!
If I wanted to add only the Mains to my listview (without adding any starters) it gives me this error.
DataMember property 'Food_Name' cannot be found on the DataSource.
I was gonna ask you something else, but I feel a bit Ridiculous...
Kind regards
Roni
|
|
|
|
|
Just to let you know I've got your message.
I no longer have Access on my system and I want to make sure that I give you correct statements, so I am writing a little application to enable me to create an Access Database.
Will get back to you shortly.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
Hi Henry
I've managed to crack the problem about the
DataMember property 'Food_Name' cannot be found on the DataSource.
I forgot to place the code on the mains click event button.
DtposDatabaseBS.DataSource = foodTable;
Now another problem is rising!
When I click the Starters button to add food items to the lits view it works fine, also
When I click the Mains button to add food items to the lits view it works fine, BUT
At the same time if I want to add another starter to my list view it doubles the item (same for main aswell),
and I think this is what coses that...
mainsUC.ItemSelected += new DtposApplication.Events.ItemSelectedEventHandler(mainsUC_ItemSelected);
I think the += sign makes it to add the double item...
Kind regards
Roni
|
|
|
|
|
Hi Roni,
Coincidentally I have just finished my Access DB Creator and run the first test against the Access DB, which works fine, but I am only testing against Starters at the moment.
With regard to your problem of the double entries, you have correctly identified the problem.
I know the answer, but am not 100% sure of the best place to put the code at the moment. Will get back as soon as I've had a think and tested it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
OK got it.
For each of your UserControls (mainsUC etc) open the whateverUC.designer.cs file, locate the Dispose() method and alter it to look like this:
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
foreach (ItemSelectedEventHandler eventDelegate in ItemSelected.GetInvocationList())
{
ItemSelected -= eventDelegate;
}
components.Dispose();
}
base.Dispose(disposing);
}
This should clear it up.
Shout out for anything else.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry
I just came back from work.
I have modified the Dispose method as you suggested, but still not working proper,
now actually it triples the items on the list view...
kind regards
roni
|
|
|
|
|
That's strange, it works for me.
Still, never mind.
A few messages ago I suggested that it would be better to have just one UserControl and add the buttons dynamically. Well, I've gone further than that. I've dispensed with the user control(s) altogether.
I've also made some other 'improvements'.
I was just uploading the new version when your message arrived. You can download it from here[^].
It is working against an Access Database
FoodTable: FoodID SmallInt, FoodName Text(30), FoodType Text(15), FoodPrice Currency
DrinkTable: DrinkID SmallInt, DrinkName Text(30), DrinkPrice Currency
Although I have not implemented the Drinks bit yet, you should be able to do that by using the same techniques as for the Food.
Let me know what you think.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|