|
The second elements of the sub-array's in your second array does not make enough sense and does not match your description.
{{1,0} {3,1} {5,2} {7,3} {9,4}} would make sense and match your description.
|
|
|
|
|
I'm sorry all, my example was poor. Yes, this is what is needed.
I can't figure out the syntax needed inside 'for'. Could you help me please?
|
|
|
|
|
warning: untested
int[] list1 = { 1, 3, 5, 7, 9 };
int[,] list2 = new int[5,2];
for (int i = 0; i < list1.Length; i++)
{
list2[i, 0] = list1[i];
list2[i, 1] = i;
}
|
|
|
|
|
Thank you. I wasn't even close & wasn't aware of 'code block' which scrambled my example.
Thanks again for your patience.
|
|
|
|
|
|
int[,] gives you a two dimensional list, not a list of pairs of numbers.
int[3,3] gives you a grid of 9 values, all of them a single int. To store pairs you'd need to define a struct, or you could use a map if you wanted ( which pairs values and lets you look up one value based on the other instead of an index ). I suspect that you're just experimenting, b/c I can't see any use for your final example ( the second value is always the same as the array index, so you have access to that number all the time anyhow ). Imagine I had a tic tac toe board for a game:
| |
___________
| |
___________
| |
Now - I can create a grid that's 3x3 with List[3,3] and I can use co-ordinates to look up positions in that list and track the game positions. That's the sort of thing a 2D array is used for.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Thank you.
I want to get:
{{1,0} {3,2} {5,3} {7,4} {9,5}}
from an original list of:
int [] list1 = { 1, 3, 5, 7, 9 };
using the increment in 'for' as the second number
|
|
|
|
|
Then you need to define a struct that contains those two numbers and build a list of them.
struct myStruct
{
public int value;
public int index;
}
will work just fine. Of course then you need to write your own code if you want to search or sort the list.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I have a datalist with an embedded dropdownlist. How can I fire an event from the dropdownlist and caclulate the results for a label in the datalist?
The datalist is similar to a shopping cart. The fore mentioned dropdownlist is the qty for each item. The total price is calculted using the qty and another field "PriceEach".
Most of the data is retrieved from a sql stored produre.
I wrote the following Item_Bound function to set the totalprice at the page_load.
protected void Item_Bound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList ddlist = (DropDownList)e.Item.FindControl("ddlQty");
Label TotPrice = (Label)e.Item.FindControl("lblTotalPrice");
Label PriceEA = (Label)e.Item.FindControl("lblPrice");
if (PriceEA.Text != null && PriceEA.Text.ToString() != "")
{
string price = PriceEA.Text.Replace("$", "");
Double dblPrice = Convert.ToDouble(price);
Double ProdQty = Convert.ToDouble(ddlist.SelectedValue.ToString());
Double ExtPrice = (dblPrice * ProdQty);
TotPrice.Text = ExtPrice.ToString();
}
}
}
|
|
|
|
|
Then what is the error you are getting... The code looks fine to me.
|
|
|
|
|
I'm trying to add code to get the qty when it is changed. I added an event to the Dropdownlist "ddlQty" called OnSelectedIndexChanged="ddlQty_Changed" and started to add the following:
protected void ddlQty_Changed(object sender, DataListItemEventArgs e)
{
DropDownList ddQty = (DropDownList)e.Item.FindControl("ddlQty");
if (ddQty.SelectedValue != null && ddQty.SelectedValue.ToString() != "")
{
Double ProdQty = Convert.ToDouble(ddQty.SelectedValue.ToString());
}
}
When I run this I get the error: No overload for 'ddlQty_Changed' matches delegate 'System.EventHandler'
|
|
|
|
|
I think the signature of ddlQty_Changed should be
protected void ddlQty_Changed(object sender, EventArgs e)
|
|
|
|
|
When I try that I can't find the "e.item" in:
DropDownList ddQty = (DropDownList)e.Item.FindControl("ddlQty");
Fixed it:
protected void ddlQty_Changed(object sender, EventArgs e)
{
foreach (DataListItem item in DataList1.Items)
{
Label TotPrice = (Label)item.FindControl("lblTotalPrice");
Label PriceEA = (Label)item.FindControl("lblPrice");
DropDownList ddlist = (DropDownList)item.FindControl("ddlQty");
if (ddlist.SelectedValue != null && ddlist.SelectedValue.ToString() != "")
{
string price = PriceEA.Text.Replace("$", "");
Double dblPrice = Convert.ToDouble(price);
Double ProdQty = Convert.ToDouble(ddlist.SelectedValue.ToString());
Double ExtPrice = (dblPrice * ProdQty);
TotPrice.Text = String.Format("${0 ,0}", ExtPrice.ToString());
}
}
}
Thanks for all the help
modified on Tuesday, November 10, 2009 3:55 PM
|
|
|
|
|
Thats nice.
|
|
|
|
|
Hello,
The question is simple but I found it tricky to accomplish.
I want to extract all the text from within the default.code node:
< default.code >
<script type="text/javascript"><!--
google_ad_client = "<?php echo($adsense_pubid);?>";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "image";
google_ad_channel = "";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "245917";
google_color_text = "555555";
google_color_url = "555555";
google_ui_features = "rc:6";
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
< /default.code >
The problem is that when I read it, the is also considered a XML node. I simply want to extract the javascript code block.
How can I do this ?
Thanks
|
|
|
|
|
The script tag IS an XML node. However you can select the default.code and select the InnerXml ( from memory ) to get the script blocks with the XML tags which also happen to be script tages.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi,
I have a habit of storing my connection string in a member of a base clase for my data access objects. That way, each object can access the database independently of each other. However, I was wondering how others handle this.
With the current way, each object is independent, but each object must maintain its own connection string value, even if its the same throughout all objects of the application.
One answer would be a static member, that way it's shared throughout all objects, but then the capability for different objects to access different databases would be lost unless the static member was constantly updated.
Thanks for any suggestions.
|
|
|
|
|
That's done in the Data Access Layer. Are you saying you do it in your business objects?
|
|
|
|
|
Nope, this is in a base class for the Data Access Layer code objects. Sorry if my post was not clear.
|
|
|
|
|
Good.
In my data access base classes[^] I hold a System.Data.IDbCommand , if I want the connection string I use this.cmd.Connection.ConnectionString ; there's no need to store it a second time.
I don't keep instantiating and throwing away connection and command instances -- that's wasteful (not that I've benchmarked it).
But now I don't know what you mean by "each object can access the database independently". What objects? I have one data access class that is basically a wrapper around one Connection/Command (with specialized versions for the various databases I use). I can instantiate one for each database and I can clone it when I need an additional connection to a particular database.
|
|
|
|
|
class base
{
string m_connString;
public string ConnString
{
get{ return m_ConnString;}
private set{ m_ConnString = value;
}
public Base()
{
ConnString = default_value
}
pubic Base(string connString)
{
ConnString = connString;
}
}
class Derived : Base
{
pubic Derived(string connString) : base(connString)
{
}
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I've got a tree view with multiple nodes added during run time and they have different images from image list.
But once you start clicking them, they change the image to recent added one.
There is somthing to do with SelectedImageKey property. How to disable such changes?
Чесноков
|
|
|
|
|
If I'm understanding you right, you want both images to be the same. A TreeNode object has two images. Once image is for the not selected and the other is for the selected/expanded view. Just set both properties to the same value.
TreeNode tn = new TreeNode();
tn.SelectedImageIndex = 0;
tn.ImageIndex = 0;
Hogan
|
|
|
|
|
Hi friends.
there is a clinic software who was written by a bankrupted company,
and now it doesn’t work by the some reason, and there is no support on this software,
All things that I have to do are recover the patient’s data that was written by doctor handwriting in his notebook tablet-pc.
let me describe a little...
software has a feature that allow to the doctor to write the patients information by hand writing with an electrical pen, it so like paint brush software and it save this information in the database like bellow...
AIfIAR0E2A/uBgIZAkgRBUgRRP8BBEgQRTUKSBFXDQAAAFD/AQQDATgAGCIgMgkA9P8CAekiOkUzCQD4nwIBWiA6RTgIAP4DAAAAgH8ADw4S+SONP88jjT8RAACAPx4+4gKD/glK/glJAAAAAAAAAAAYyAAAAAAAAAAAAAAAAAiQIkAAAAAAVMgAAAAESAEJAAAAAAxkAAAAAAIfEAAKLw+E+44+492VloilKFtOjSCG4PDhA6KAjpKCkI
i found that, it's definitely a String Base 64, 'cause I was able to build a byte array from it with this code:
string strData = dataGridView1[2, 0].Value.ToString();
byte[] data = Convert.FromBase64String(strData);
and then i use this :
public Image ByteToImageConvert(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
but i face with this problem on " Image returnImage = Image.FromStream(ms);":
Parameter is not valid.
So What should i do?
i attached the database file here/:
http://rapidshare.com/files/302706380/test.accdb.html
there is a tables in the database, and all thing that i need is the "VISIT Table" 's information on the column by the name "NOTES", i think it must be image.
HELP ME,THis IS UrGENT Problem!
thank you very much!
With best Regards!
modified on Thursday, November 5, 2009 7:36 PM
|
|
|
|
|
Forgive me if I seem a bit dense..... I am unable to find a question anywhere in your post nor could I find any relevance to C#.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|