|
I was trying to get my PC's IPv4 address...
|
|
|
|
|
You probably need them both, since the GetHostEntry needs the host name to work from. Either that or the IP address, which (given that that is what you are trying to get) you probably haven't got...
Have a look at this: Retrieving IP and MAC addresses for a LAN[^] It does more than you need in that it returns the IP and MAC for your PC as well as that info for other LAN based devices, but it's pretty clear how it works.
[edit]Typo: "guven" for "given" - OriginalGriff[/edit]
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hi,
I am dynamically creating Dropdownlist on server side like this:
Default.aspx page code:
Default.cs.aspx code:
On Page_Load()
{
test();
}
private void test()
{
string str = string.Empty;
str += "";
str += "ABC";
str += "EEE";
str += "EEEE";
str += "DEE";
str += "";
dropdownList.InnerHtml = str;
}
private void Save()
{
DropDownList drp = (DropDownList)this.FindControl("ddl_11");
string str = drp.SelectedValue;
}
While saving i want to get the selected value of dynamically created dropdownlist. but when i am debugging code and found that FindControl() didnt find the "ddl_11" on page its giving me NULL value.
How can i find the dynamically created dropdownlist?
Please help me i am stucked on this from last one week and didnt find any solution please help me guys.
~~~Charanjot Singh~~~
|
|
|
|
|
Hi guys, I have a FlowLayoutPanel containing unspecified number of Label ,when double click in one of them, a new Form containing a TextBox and a Button will appear, here is the code:
...
foreach (Label lb in FlowLayoutPanel1.Controls)
{
lb.MouseDoubleClick+=new MouseEventHandler(lb_MouseDoubleClick);
}
...
private void lb_MouseDoubleClick(object sender, MouseEventArgs e)
{
NewForm form = new NewForm();
form.ShowDialog();
((Label)sender).Text = ...;
}
I want get Text from TextBox of the NewForm and assign Text to the object that invoke the Form when user click the Button of the Form, I don't know how to use delegate to do this, please help! Thanks for reading this!
|
|
|
|
|
You could loop through the Controls collection of the new form, looking for the text box. Then read its text property.
foreach (Control C in form.Controls)
if (C is TextBox)
((Label)sender).Text = ((TextBox)C).Text;
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thank Richard, but is there another way using delegate? I want to know it for learning purpose.
|
|
|
|
|
Sorry Richard, but that is a very bad idea! Just because Microsoft declare the Controls array as public doesn't mean you should use it for a simple task as it locks the design of the two forms together - you can't change NewForm without considering any effect it might have on existing code. Using a Property to access the data in NewForm is a much more OOPs solution!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
You wouldn't use a delegate for that - you would use a property in the NewForm instead.
public string Text
{
get { return myTextBox.Text; }
set { myTextBox.Text = value; }
} To even try to use a delegate for that is overcomplicating things, and opening up a route to problems.
Delegates are very powerful, but they shouldn't be used when there are better alternatives!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thank you OriginalGriff, that's a good idea ,just because I want to understand delegate more carefully.
|
|
|
|
|
You're welcome!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
What hasn't been mentioned to you is why you wouldn't use a delegate here. Basically, ShowDialog is a blocking operation so the new form blocks the originating form until it has finished processing, so retrieving the value from a known property is a much better option.
|
|
|
|
|
So we can't use delegate if using ShowDialog(), in all cases? Thank Pete!
|
|
|
|
|
Hello The Code Project
I need help on a project, i have an Access 2010 Database and i want to fill a combo box with one column named "Telephones" From a Table named "SIM"
I've tryed so many ways but i dont know why i can't make it work
Examples:
private void llenarElementos()
{
cbo_codsim.Items.Clear();
int filascod = base_Gps_InfoDataSet.Tables["SIM"].Rows.Count;
for (int y = 0; y < filascod; y++)
{
cbo_codsim.Items.Add(base_Gps_InfoDataSet.Tables["SIM"].Rows[y][1].ToString());
}
}
i'm calling that function on the form load..
Also i've tryed to do it by selecting the bindingsource and the table in VS but data don't appear.
If you all need the full code just ask
PD: VS 2008 SP1
Please Help :/
|
|
|
|
|
DJCRIS12 wrote: I've tryed so many ways but i dont know why i can't make it work
When you say it's not working, what does that mean? it errors, or you get no data, or the combo box it's populating?
If it's not broken, fix it until it is
|
|
|
|
|
sorry i've solved the issue, my database wasn't recogniced like suposed to be
thanks anyways !
|
|
|
|
|
Hi everyone! I need to insert text into a WebBrowser control dynamically. I'm thinking it may be possible using Javascript but my problem now is that I don't know how this is done using C#. Any tutorials please? Thanks.
|
|
|
|
|
There are at least two ways to get some text displayed by a WebBrowser Control:
1.
create an HTML page with whatever content you like, then have the WebControl Navigate to it. This requires an HTTP server, which you could embed in your application itself, see e.g. here: Sample HTTP Server Skeleton in C#[^]
2.
Much easier is to feed the HTML document straight to the WebBrowser.DocumentText property.
Neither of these let you just append text to existing text, as HTML code isn't "appendable"; it requires correct closing BODY and HTML tags at the end.
|
|
|
|
|
Luc Pattyn wrote: This requires an HTTP server
No it doesn't! All you need to do is to save it to disk and navigate to a file system url:File URIs in Windows[^].
Sample: file:///C:/Documents%20and%20Settings/davris/FileSchemeURIs.doc
Cheers!
"With sufficient thrust, pigs fly just fine."
Ross Callon, The Twelve Networking Truths, RFC1925
|
|
|
|
|
You're right of course, however I'm not going to suggest to cause continuous disk activity just to show a growing page of text in some Control.
|
|
|
|
|
You could use an AJAX-call using JavaScript. You'd still need to embed everything in a HTML-document, but that would be the way to get dynamic content on a page.
Start here[^].
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Take a look at the Document.InvokeScript method of your WebBrowser control. You can execute all the Java Script you want dynamically. Mix that with the ObjectForScripting method and you can handle call backs also.
I encapsulated google maps into Windows Forms using this method and it has been flawless.
|
|
|
|
|
Thanks all. I will try all suggested solutions and see if they will suit my work.
However, what may be another problem considering the suggestions is that the application is not aware of the text that will be inserted into the page. All text will be generated as the user is using and interacting with the application. I don't know how I can accomplish that.
|
|
|
|
|
Ok, I will go a step further. There is nothing in the DOM that you cannot alter dynamically with InvokeScript. If you can do it in HTML, you can do it with C#. Here is an example of changing a
<H id="myHeader"> element.
public void UpdateHeader(string data)
{
string cmd = "var x=document.getElementById(\"myHeader\"); x.innerHTML = \"{VAR}\";"
cmd = cmd.Replace("{VAR}", data);
object[] codeString = {cmd};
webBrowser1.Document.InvokeScript("eval", codeString);
}
|
|
|
|
|
Thanks Potter. In this case, should "eval" be a script that should exist on disk in the application folder? I checked the arguments to InvokeScript and the first argument is name of the script.
|
|
|
|