|
Hi,
i am working in windows application of C#
i am using hash table.
i want to add data to hash table from datatable named DTSchool. I have a school name in combobox. when iselect school in combo it takes the curresponding SchoolID from the datatable
i want to know how to write code for that. i wrote like this
List.Add(SchoolDT.Rows[cboSchool.SelectedIndex]["SchoolID"],cboSchool.Text.ToString());
.But it is not taking value from datatable.Please help me regarding this problem?
|
|
|
|
|
I doubt this is a syntax problem. If it was the compiler would be complaining. You have a run time error.
sajin85 wrote: cboSchool.Text.ToString()
Why are you calling ToString() on something that is already a string?
Are the rows in the DataTable order the same way as the items in the combo box?
|
|
|
|
|
Hi,
Are you sure the indexes of the items in your combobox matches the row indexes in your datatable?
Maybe posting a little bit more code might help to tackle your problem.
Mark
|
|
|
|
|
Hi
Anyone who knows how to add filetype programmatically in media player ?
For instance: The player accept .wav but i wish to set the player so it also accept .mp3, programmatically.
Any ideas ?
I tried msdn but dont find anything
With regards
Heino
|
|
|
|
|
Do you mean create a file association so that when you double click on an mp3 it opens with WMP11? If so, that requires some registry hacking - check here[^]; this article simplifies things a bit by providing a wrapper for the registry nastiness
|
|
|
|
|
Hmmmm....maybe.
What i meant is that if you start WMP from startmenu then you have the chance to set filetype by going thru the menu: TOOLS > OPTION and then the tab FILE TYPES.
Yes...so maybe this should do it then
I will give it a try.
Thanks for your help
Heino
|
|
|
|
|
hi there,
i m trying to find string but its irritating me, dont working as i want
i dont know where i did mistake,here is the codes
int isthere = -1;
int quan = 0;
int[] selectedindxes = new int[subtypeCmb.Items.Count];
int check = -1;
for (int a = 0; a < subtypeCmb.Items.Count; a++)
{
check = -1;
check = subtypeCmb.FindStringExact("ABC", isthere);
if (check != -1)
{
isthere = subtypeCmb.FindString("ABC", isthere);
selectedindxes[quan] = isthere;
quan++;
}
}
"ABC" is on 3rd item of combobox and 'check' is always 2, however its assigning -1 in every loop
the no of "ABC" item in combobox is 1, so 'quan' should be 1, but it always show 8 as total items in combobox is 8
can someone tell me where is mistake
i tried it with all ways i can but problem persist
Becoming Programmer...
|
|
|
|
|
Hi,
why do you need a for loop?
You search the ComboBox by just calling FindStringExact, and it finds one occurence.
You repeat it 8 times, so you find the same thing 8 times...
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
i m using loop because i want to search all items in the combobox named "ABC"
i put 'quan' to get the number of items find in the combobox
i got another way to do that what i want but the findstring method not working correctly with overload of 'startposition'
Becoming Programmer...
|
|
|
|
|
Hi,
as I said you don't need the for loop, and you don't need subtypeCmb.Items.Count
if you want to find all occurences, what you need is a while loop ("while there is more")
based on the correct use of FindStringExact and startIndex. I suggest you reread the MSDN
page on FindStringExact
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I need sugge./ advice for video processing for bleow requirement
Person or object will be selected in the first frame of video sequence
manually by mouse. Now the selected object/persion should be segmented in
rest of the frames by the algorithm/porgram.
any souce code/algorithm/ links / suggestion are greatly appericated
Thanks in advance
->electron
|
|
|
|
|
Take a look at Andrew's articles. Particularly the Motion Detection Algorithms article, sounds like exactly what you want to do.
|
|
|
|
|
- Could u share your ideas?
My intent is to download more than 100 files from web server. Assume that my web server is http://111,222,333,444/ and i have 100 files(with small size) named "A1","A2"..."A100" within Data folder likes
http://111.222.333.444/Data/A1 .
Which is the best way to download all of these files with highest connection speed?
Because of i applied WebRequest , WebResponse, and multi-threading(1 thread for 1 file),it has too long delay when connect to each file.Could u give me an adviced how to do this?
This is my sample code.
<br />
ArrayList filenameList=new ArrayList();<br />
filenameList.Add("http://111.222.333.444/Data/A1");<br />
filenameList.Add("http://111.222.333.444/Data/A2");<br />
filenameList.Add("http://111.222.333.444/Data/A3");<br />
...<br />
filenameList.Add("http://111.222.333.444/Data/A10000");<br />
<br />
for(int i=0;i<filenameList.Count;i++)<br />
{<br />
Thread workThread=new Thread(new ParametrizeThreadStart(downloadMethod));<br />
workThread.Start(filenameList[i]);<br />
}<br />
<br />
public void downloadMethod(object TargetUrl)<br />
{<br />
string Target=TargetUrl as string<br />
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Target);<br />
req.Timeout = 100000 * 3;<br />
req.Proxy = new WebProxy(new Uri("http://localhost:3128"));<br />
resp = (HttpWebResponse)req.GetResponse();<br />
Stream stm = resp.GetResponseStream();<br />
int ReadCount;<br />
byte[] buffer = new byte[65535];<br />
FileStream f = File.Open(SaveDirectory + "/" + filename, FileMode.Create<br />
, FileAccess.Write, FileShare.None);<br />
if (stm.CanRead)<br />
{<br />
while ((int)(ReadCount = stm.Read(buffer, 0, buffer.Length)) > 0)<br />
{<br />
f.Write(buffer, 0, ReadCount); <br />
} <br />
}<br />
f.Flush();<br />
f.Close();<br />
}<br />
Likes that,the main problem is "resp = (HttpWebResponse)req.GetResponse();" becuase it has too much delay time.
Can i use multi-threading like this? Are there better way?
Thank
=)
-- modified at 6:40 Wednesday 12th September, 2007
|
|
|
|
|
My suggestion is to start for instance 4 threads that each take 1 entry from the list (and remove it from the list) and download that particular file. Once the file is downloaded it takes the next entry from the list and download that and so on. Once the list is empty the thread can just terminate. Personally I would use the ThreadPool for the threads since you do not need to clean those up manually.
Hope that helps,
Mark
|
|
|
|
|
You can use multi-threading, but you are going to run into problems due to limitations in the TCP/IP stack as implemented by Microsoft. The TCP/IP stack only allows a certain number of concurrent operations, so you aren't going to see the performance you are expecting. (You can verify this by trying to download more than 2 or 3 large files at one time through Internet Explorer. After the 2nd or 3rd download, the next one you click will sit and wait until it either times out or an earlier download finishes.)
You might want to check out this article[^] as well. It provides a component you can use to asynchronously download a file.
|
|
|
|
|
Thank for ya help.=)
but i have another questions.
1. As you can see that A1..A10000 files are in the same folder "http://111.222.333.444/Data" but with HttpWebRequest and HttpWebResponse i have to create connection to every files(too long delay time wait for each connection.) instead of just create connection to "http://111.222.333.444/Data" and download files within it.
Is it possible just create one connection to "http://111.222.333.444/Data" then start download files within it? how?
2. The speed is important for this project,so i need to known which is the best way to gain th highest performance between syncronized (multi-threading) and asyncronized(async-threading or download just one file at one time)?
|
|
|
|
|
HTTP is inherently a stateless connection, and only keeps a connection open long enough to transfer the data. Using any of the HttpWeb classes, you won't be able to open a connection to a folder and then download files. You need to open a connection for each file you want to download.
In general, any time you are doing disk I/O operations (like saving the file as it is being downloaded) you should use async calls.
To do what you want you would need to program directly at the socket level, which is possible but not trivial.
If you have control over the files at the other end, you could create an archive of the files and download that instead of each individual file.
|
|
|
|
|
|
I have two forms. Form1 has a textbox and a button. Form2 has a label. When the button on form1 is clicked, form2 is opened and the text in the textbox in form1 is shown in the label of form2. To get the text in the textbox to appear in the label, the code I have for this is in the Form load event. In this event I want to check if the button on form 1 has been clicked. How do I do this?
I can access the button (located on form1) from form 2 by firstly making this public and then using this code:
((Form1)frm1).button1.
I do not know how to finish this line of code while it is in an IF statement.
Lucy
|
|
|
|
|
You can create a bool variable in Form1 and set it to true in the click event handler of your button. Then check it's value from your method in Form2.
|
|
|
|
|
Sorry I'm not sure how to do that. Can you explain your answer please?
Lucy
|
|
|
|
|
Events and delegates.
Either get Form2 to subscribe to Form1.Button's onclick event or capture the onclick event on form1 and tell Form2 it has been clicked using a delegate :-
<br />
public Event Eventhandler OnButton1Click;<br />
<br />
void form1_buttonClicked( objects sender , EventArgs args)<br />
{<br />
<br />
if (OnButton1Click != null)<br />
OnButton1Click( sender , args );<br />
}<br />
<br />
<br />
public void MyHandler( object sender , EventArgs args)<br />
{<br />
}<br />
<br />
<br />
<br />
form1.OnButton1Click += MyHandler;<br />
<br />
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"I haven't spoken to my wife now for 48 hours. I don't like to interrupt her.
|
|
|
|
|
set modifiers of your form2`s label to "public" in properties
then in button`s click event ,writes these codes
form2 frm = new form2();
frm.label2.Text = textbox1.Text;
frm.Show();
hope it will help...
Becoming Programmer...
|
|
|
|
|
I have tried that but it comes up with this error when you click the button:
Additional information: Object reference not set to an instance of an object.
I do not understand the other comments people have made as I am still very new to c#.
Lucy
|
|
|
|
|
i think you are clicking button when your textbox value is null
Becoming Programmer...
|
|
|
|