|
hello all,
I am new to C# and would like your help in this matter.
I know this is the syntax to declare a single dimensional arraylist in C#
ArrayList arraylist_name = new ArrayList().
Can anybody tell me as to how I can declare a 2 dimensional arraylist and access the same?
Thanks in advance.
Keshav V. Kamat
Systems Engineer
Siemens
India.
|
|
|
|
|
The best way to create that is to use the hashtable, although its a map and not a list you can still access the keys as if they were a list of values.
Hashtable table = new Hashtable();
To create a two dimensional arraylist you will have to write something like this:
ArrayList list1 = new ArrayList();
for(int x = 0; x < 10; x++) {
list1.Add(new ArrayList());
}
but this uses significant more memory and is not advisable if you only need the first lists index to access the second list. In that case you are better of with a hashtable that uses an Int32 value as key and ArrayList as value.
WM.
What about weapons of mass-construction?
|
|
|
|
|
thanks.
i will try that out.
Keshav V. Kamat
Systems Engineer
Siemens
India.
|
|
|
|
|
Ther are 2 things you could do.
1) If you know the size of the dimention you want to create, you could make an array of ArrayList.
ArrayList []list = new ArrayList[10];
for( int i = 0; i < 10; i++ )
{
list[i] = new ArrayList();
}
2) If you want a variable length (dont know the length) you could create an ArrayList of ArrayLists.
ArrayList list = new ArrayList();
ArrayList subList = new ArrayList();
list.Add(subList);
|
|
|
|
|
ArrayList list = new ArrayList();
ArrayList<string> list2 = new ArrayList<string>();
for the normal array its
String[] strings = new String[10];
WM.
What about weapons of mass-construction?
|
|
|
|
|
Thanks for the reply.
But I dont think you got my question right.
I dont want to declare 2 single-dimensional arrays separately.
I want to declare a 2-dimensional array like the one you do with the normal array like this
string[,] string_name=new string[10,10];
See if you know.
Keshav V. Kamat
Systems Engineer
Siemens
India.
|
|
|
|
|
Hmm, something is up with the post
I just saw two posts and now there's just one... Ah well, must be me sleeping again. See the answer posted earlier
WM.
What about weapons of mass-construction?
|
|
|
|
|
Hi
how can i add avi files to my application.
is three any control for this purpose
|
|
|
|
|
Hi,
in the directx library,
there exist a video library,
that you play, forward, reward, gather the current position,
total duration properties and methods like play pause stop.. etc..
just downlad the directx latest sdk...
but it is a little big size to download...
|
|
|
|
|
I want to set the datetime format in gridview control column.
|
|
|
|
|
HI
when i open a flderbrowse dialog box and select folder
"F:\Documents and Settings\Parshant\Local Settings\Application Data\Identities\{9A42BBED-20C1-4620-9381-F7ACFB5D1809}\Microsoft\Outlook Express"
then it throw a exception "invalid access to memory location"
But when select at another location it works perfect.
i written the code
DialogResult result = folderBrowserDialog.ShowDialog();
if(result==DialogResult.OK)
lbl_dbx_folder_info.Text=folderBrowserDialog.SelectedPath.ToString();
Parshant
|
|
|
|
|
HI,
you either don't have access to that folder or it is simply not found.
jamil abou khalil
|
|
|
|
|
But in case of "openfiledialog"
file is simply seleted in side
"F:\Documents and Settings\Parshant\Local Settings\Application Data\Identities\{9A42BBED-20C1-4620-9381-F7ACFB5D1809}\Microsoft\Outlook Express"
no exception thrown.But in folderbrowsedialoge problem occure.
plz help
|
|
|
|
|
Hello All,
I have a user control. which contains a tree view as well as list view control. One at a time will show. I have problem with ListView. I am adding item in at runtime on OnDraw method. I have also override OnMesureItem. Now i want to clear the the item. But there is some problem with it. When i click on submit button, old items should cleared and new ones should be added. But when i click on submit button. The new items added to the list , they are not getting cleared.
I used:-
Item.Clear();
Can anybody help me.
|
|
|
|
|
How do we create events for a user control which is dynamically added?
Thanks in advance
R.K
|
|
|
|
|
In Your control which is too added class;-
Declare delegate:-
public delegate void ShowTextEvent(string str,EventArgs e);
Declare event:-
public void ShowTextEvent MyEvent;
/////////////////////////////////////////////////////////////////////
void somemethod()
{
//////////////////////////////// Control is added
Controls.Add(NewControl);
/////////////////////////////// Setting Event to this.
NewControl.MyEvent+=new ShowTextEvent(OnMyEvent);
}
////Handler
void OnMyEvent(string str,EventArgs e)
{
}
|
|
|
|
|
Hi aslam,
i have a user control created with a button on it.
I am creating an instance of this user control using statments
IComponent newComponent = Activator.CreateInstance(componentClass, objparams) as IComponent;
now i need to add event to this component.
i want the click event of the user control.
please help.
thanks in advance.
|
|
|
|
|
how can i change tags in xml file such as attachment picture with another one automaticly when another attachment arrive to some folder such that i have a attachment picture name rrr.jpg and i want a program to change the name of the attachment when a new picture arrive to a folder and replace it with the new pic that arrive if any as a loop every 30 sec to check if there is a new pic and replace it with the arrived pic and also save the xml file after modification in spicific location and also if the program could replace the old pic with the new one and the program must run always and check for new pic and i hear that this could be done using C# so if any body can help me thatwill be so nice thanks for your time
moadbrkt
|
|
|
|
|
moadbrkt wrote: how can i change tags in xml file such as attachment picture
Use XMLDocument to load your XML String or XML File and then iterate on it and when you reached the desired node use InnexText to set the new text.
moadbrkt wrote: the program must run always and check for new pic
Try using a WindowsService
Do your best to be the best
|
|
|
|
|
no i want to change the tags automticly
|
|
|
|
|
I need to use it to show data for products or shops
As I’m making a e-commerce site
So, I want to know how I use the repeater in a dynamic way
To support the rows that was selected
And to target every column in a label and to put the title beside it
Thanks for help!
Ah_Mohsen
|
|
|
|
|
Wrong forum, it should be in the ASP.NET forum.
But:
in the aspx file:
<br />
...<br />
<asp:Repeater ID="MyRepeater" runat="server"><br />
<ItemTemplate><br />
<br />
<%# ((MyProductClass)DataItem.Container).ProductName %><br />
<br />
</ItemTemplate><br />
</asp:Repeater><br />
<br />
...<br />
in the .cs file
Page_Load()
{
...
List<MyProductClass> products = MyProductClass.GetProductListFromDatabaseOrSomething();
MyRepeater.DataSource = products;
MyRepeater.DataBind();
...
}
it's usual practice to put the above code within a if (!IsPostBack) {... } block so that it only gets loaded on the first page load rather than after every postback.
Hope that helps,
ChrisB
|
|
|
|
|
Sorry, the first block should read:
<br />
...<br />
<asp:Repeater ID="MyRepeater" runat="server"><br />
<ItemTemplate><br />
<br />
<%# ((MyProductClass)DataItem.Container).ProductName %><br />
<br />
</ItemTemplate><br />
</asp:Repeater><br />
<br />
...<br />
|
|
|
|
|
I put this in m code:
public class Row : System.Windows.Forms.ListViewItem<br />
{<br />
public int id;<br />
public int online;<br />
}
And have this code
ListViewItem item = new ListViewItem(new string[] {reader[NAME].ToString(), reader[GAME].ToString(), reader[BNAME].ToString(), reader[BOARD].ToString()});<br />
Row row = (Row)item; <-- ERROR OCCURS HERE<br />
row.id = Convert.ToInt32(reader[ID].ToString());<br />
row.on1ine = Convert.ToInt32(reader[ONLINE].ToString());<br />
MainForm.listView1.Items.Add(row);
But i get the above error, that it couldn't cast ListViewItem as Row. Ive done this before with TreeNode and it all worked fine, what wrong with this one?
Why did my row.online get replaced with row.removed, it doesn't do it outside the code brackets?
-- modified at 20:31 Tuesday 10th October, 2006
|
|
|
|
|
I'm now just storing row in item.Tag, and it works (of course) but i still want to know why this won't work, i just can't see it.
|
|
|
|