|
I have a menustrip like as
a
b
c
i wanna to add a new menuitem in this menu named as d from database
and now my menustrip is looks like
a
b
c
d
now m wanna to add another menuitem in this menu as e from database
but now my menu shows
a
b
c
d
a
b
c
d
e
but i wanna tht my menu shows as
a
b
c
d
e
can anyone help me in it
|
|
|
|
|
Show the code you are using; we cannot guess what is going wrong from the above.
Use the best guess
|
|
|
|
|
public void SubMenu(ToolStripMenuItem menuitem, string submenu)
{
string get_subcatagory = "select * from medicine_subcatagory where Cat_ID=(select Cat_ID from medicine_catagory where Med_Cat='" + allopathicToolStripMenuItem.Text + "')";
DataTable dt = d.getdata(get_subcatagory);
foreach (DataRow dr in dt.Rows)
{
ToolStripMenuItem ssmenu = new ToolStripMenuItem(dr["Med_Sub"].ToString(),null, new EventHandler(ChildClick));
if (menuitem.DropDownItems.Contains(menuitem.DropDownItems[dr["Med_Sub"].ToString()]))
{
menuitem.DropDownItems.Remove(ssmenu);
}
else
{
menuitem.DropDownItems.Add(ssmenu);
}
}
}
thats he code i use for add submenu in menuitem
|
|
|
|
|
And what happens when you step through it in your debugger? Although, at a guess it is failing the if expression.
BTW please indent your code and put <pre> tags round it, so it looks like:
public void SubMenu(ToolStripMenuItem menuitem, string submenu)
{
string get_subcatagory = "select * from medicine_subcatagory where Cat_ID=(select Cat_ID from medicine_catagory where Med_Cat='" + allopathicToolStripMenuItem.Text + "')";
DataTable dt = d.getdata(get_subcatagory);
foreach (DataRow dr in dt.Rows)
{
ToolStripMenuItem ssmenu = new ToolStripMenuItem(dr["Med_Sub"].ToString(),null, new EventHandler(ChildClick));
if (menuitem.DropDownItems.Contains(menuitem.DropDownItems[dr["Med_Sub"].ToString()]))
{
menuitem.DropDownItems.Remove(ssmenu);
}
else
{
menuitem.DropDownItems.Add(ssmenu);
}
}
}
Use the best guess
|
|
|
|
|
yes it always goes into else code
|
|
|
|
|
Then you should be able to see how to fix it fairly easily.
Use the best guess
|
|
|
|
|
i dont know how to do it...
Can u help me in it...
just giv me a simple concept about how cud i check tht a particular menuitem, which is already get from database, exist over there and thn how to add new menuitem from database into that previously created menu.....
|
|
|
|
|
A quick glance at the documentation[^] suggests that you are testing against the wrong object type.
Use the best guess
|
|
|
|
|
thanks richard i solved my problem now
|
|
|
|
|
Dear All,
I am editing some lines in aP text file using c#, while editing the (') is replacing with another new charachter, i dont want this can any one help with code
StringBuilder newFile = new StringBuilder();
string temp = "";
string[] AllLines = File.ReadAllLines(FileName);
strStart = "<";
foreach (string strLine in AllLines)
{
if (strLine.Contains("CUsers") || strLine.Contains("_ags"))
{
fIndex = strLine.IndexOf(strStart);
sIndex = strLine.LastIndexOf("_ags");
temp = strLine.Remove(fIndex + 2, (sIndex - fIndex) + 2);
newFile.Append(temp + "\r\n");
continue;
}
newFile.Append(strLine + "\r\n");
}
File.WriteAllText(FileName, newFile.ToString());</pre>
Thanks in advance,
Srikanth
srikanth
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
static void Main(string[] args)
{
StringBuilder newFile = new StringBuilder();
string temp = "";
string[] AllLines = { "This <_ags> a' test?" };
string strStart = "<";
foreach (string strLine in AllLines)
{
if (strLine.Contains("CUsers") || strLine.Contains("_ags"))
{
int fIndex = strLine.IndexOf(strStart);
int sIndex = strLine.LastIndexOf("_ags");
temp = strLine.Remove(fIndex + 2, (sIndex - fIndex) + 2);
newFile.Append(temp + "\r\n");
continue;
}
newFile.Append(strLine + "\r\n");
}
Console.WriteLine(newFile.ToString());
Console.ReadKey();
}
} Can you change the "AllLines" variable to reflect your textfile contents, and show us an example of the output you'd expect on that? The code above would result in
This <_> a' test?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
for exmple in a file the text is like
We’re actually going to increase your savings to $40 cash back!
We’re '<$40 _agscash back!
after executind my code
out put is comming as
We?re actually going to increase your savings to $40 cash back!
We?re cash back!
in the above (') is replacing with (?) automatically
actually out put i need is
We’re actually going to increase your savings to $40 cash back!
We’re 'cash back!
|
|
|
|
|
srikanth kamuju wrote: n the above (') is replacing with (?) automatically I don't see any code that would do that. Sounds like a problem with the encoding; where are you viewing the string? Using notepad? Is it saved as UTF?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Open notepad, press Ctrl-O . There a dropdownlist under the filename, labeled "enconding". Verify that it's set to UTF and not to ANSI. Then open the file again.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes that encoding is the culprit... See my answer below
|
|
|
|
|
srikanth kamuju wrote: in aP text file using c#,
Please give a sample what you want to do... perhaps i'll be able to hep you better.
Do you want to remove "_args" (minus quotes) from your lines...??
|
|
|
|
|
for example in a file
We’re actually going to increase your savings to $40 cash back!
We’re '<$40 _agscash back!
after executind my code
out put is comming as
We?re actually going to increase your savings to $40 cash back!
We?re cash back!
in the above (') is replacing with (?) automatically
actually out put i need is
We’re actually going to increase your savings to $40 cash back!
We’re 'cash back!
|
|
|
|
|
This is clear,,,
I read in 9th grade of my school that in java and c, ' needs to be escaped as \'. Since c# is a descendant of c, guessing it might be the problem. Try replacing (')s in your code with (\')s. See if it works.
EDIT:
Ignore the above... I figured out the problem
You have used ’ (backquote). It's not a part of standard windows codepage, so it is displayed as "?". Save yout text as UTF8 and write as UTF8 too. Notepad++ is a good tool to convert and edit text files.
Here's some code... how I did it
using System;
using System.Text;
using System.IO;
class Program
{
static void Main(string[] args)
{
StringBuilder newFile = new StringBuilder();
string temp = "";
string[] AllLines = File.ReadAllLines("new.txt",Encoding.UTF8);
string strStart = "<";
foreach (string strLine in AllLines)
{
Console.WriteLine(strLine);
if (strLine.Contains("CUsers") || strLine.Contains("_ags"))
{
int fIndex = strLine.IndexOf(strStart);
int sIndex = strLine.LastIndexOf("_ags");
temp = strLine.Remove(fIndex + 2, (sIndex - fIndex) + 2);
newFile.Append(temp + "\r\n");
continue;
}
newFile.Append(strLine + "\r\n");
}
Console.WriteLine(newFile.ToString());
File.WriteAllText("new2.txt", newFile.ToString(),Encoding.UTF8);
}
}
NOTE: your file needs to be encoded in UTF8 or it will result in garbled text!
TIP: Use a regex to replace... Its easy and less complicated.
modified 30-May-13 6:00am.
|
|
|
|
|
That is only necessary in strings inside the source code; not in files that are read and written.
Use the best guess
|
|
|
|
|
Oh! I didn't read the contents of the text files properly (sorry... ) now it is edited and fixed!
|
|
|
|
|
hi friends i have problem in deploying c# window application in vs2010 with sap crystal report 13.0 some error if any one have solu plz help me
crystal report can't open in client side
modified 30-May-13 4:37am.
|
|
|
|
|
You have provided no error description at all.
With this little information, no one would be able to help you.
|
|
|
|
|
Hi,
Hi have a question on classes that contains lists, and going to try hard not to make you confused.
If I have three classes:
public class Customer
{
public string CustomerCode { get; set; }
public List<warehouse> CustomerWarehouses { get; set; }
}
public class Warehouse
{
public string Name { get; set; }
public List<stock> StockCodes { get; set; }
}
public class Stock
{
public string StockCode { get; set; }
public string Description { get; set; }
public int QtyAvailable {get; set;}
}
The program starts by Populating the Customer Class.
So I will have CustomerCode "CUS123".
Then I select warehouses I want to check stock, "A1" and "B1".
So at this stage I will have the Customer Class containing customer "CUS123" and two warehouses "A1" and "B1".
Then I read stock from an excel file. Let's say I read stock code "CODEABC123".
Then for each warehouse I want to check stock and add it to the warehouse class in StockCodes list.
So warehouse "A1" and "B1" must have the stock code with their own values.
This is the code I have to populate the StockCodes list in the Warehouse Class:
public List<stock> GetStockCodeWarehouseInfo(List<stock> StockList, Customer CustomerInfo)
{
Stock tempStock = null;
foreach (Warehouse warehouse in CustomerInfo.CustomerWarehouses)
{
foreach (Stock stockcode in StockList)
{
tempStock = new Stock();
tempStock = stockcode;
//Get additional stock info
tempStock = GetAdditionalStockInfo(warehouse.Name, tempStock);
}
tempStockList.Add(tempStock);
warehouse.StockCodes.Add(tempStock);
}
return StockList;
}
When the Stock Code is added to the first Warehouse ("A1") StockCodes list the values are correct.
After the Stock Code is added to the second Warehouse ("B1") StockCodes list the first warehouse values for Stock Code is the same as values in Warehouse "B1".
So to put this in simple terms:
After Stock Code is added to first warehouse, I will have:
Customer.Name = "CUS123"
Customer.Warehouse.Name (LIST) = "A1"
Customer.Warehouse.StockCode = "CODEABC123"
Customer.Warehouse.Description = "A STOCK CODE"
Customer.Warehouse.QtyAvailable = 10
After Stock Code is added to second warehouse, I have:
Customer.Name = "CUS123"
Customer.Warehouse.Name (LIST) = "B1"
Customer.Warehouse.StockCode = "CODEABC123"
Customer.Warehouse.Description = "A STOCK CODE"
Customer.Warehouse.QtyAvailable = 5
Customer.Name = "CUS123"
Customer.Warehouse.Name (LIST) = "B1"
Customer.Warehouse.StockCode = "CODEABC123"
Customer.Warehouse.Description = "A STOCK CODE"
Customer.Warehouse.QtyAvailable = 5
Where I should have:
Customer.Name = "CUS123"
Customer.Warehouse.Name (LIST) = "A1"
Customer.Warehouse.StockCode = "CODEABC123"
Customer.Warehouse.Description = "A STOCK CODE"
Customer.Warehouse.QtyAvailable = 10
Customer.Name = "CUS123"
Customer.Warehouse.Name (LIST) = "B1"
Customer.Warehouse.StockCode = "CODEABC123"
Customer.Warehouse.Description = "A STOCK CODE"
Customer.Warehouse.QtyAvailable = 5
Ay ideas on what I am doing wronng?
Thanks
|
|
|
|
|
You're not creating two lists, you're just changing the values. Also, you are not using strongly typed lists - that isn't causing your problem, but you should change to that.
public class Customer
{
public string CustomerCode { get; set; }
public List<Warehouse> CustomerWarehouses { get; set; }
}
public class Warehouse
{
public string Name { get; set; }
public List<Stock> Stocks { get; set; }
}
public class Stock
{
public string StockCode { get; set; }
public string Description { get; set; }
public int QtyAvailable {get; set;}
}
Note that I changed the name of the "StockCode" list because it is not containing StockCodes, it contains Stock objects. Given that class structure, if you wanted to create two warehouses, A1 and B1, and put one Stock item in each, you need to be careful how you create your lists - you haven't provided any method of initializing them in your classes. You didn't write constructors in these classes, so your List objects start out NULL.
Here's sample code to create two warehouses with one item each...
Create a constructor for the Customer object, to initialize your lists...
public class Customer {
public Customer() {
CustomerWarehouses = new List<Warehouse>();
}
public string CustomerCode { get; set; }
public List<Warehouse> CustomerWarehouses { get; set; }
}
Now, when you create a Customer object, you have a list ready to go, but it contains NO Warehouse objects - you'll have to add one. Can you see where I'm going with this? Think it out in steps and code up those steps - then post all your code if you're still having problems, your original question doesn't include the code we need in order to answer it. SHOW how you're populating these objects.
|
|
|
|