|
i think you are clicking button when your textbox value is null
Becoming Programmer...
|
|
|
|
|
No the error still occurs when the textbox has text in it.
|
|
|
|
|
you are doing some mistakes
Becoming Programmer...
|
|
|
|
|
Yup - one of the first mistakes is making a control public. You really shouldn't make controls public because you have opened up the whole scope of what the control can do to another unrelated instance.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Another way is like this:
Add another Label to your class variables:
private System.Windows.Forms.Label Form2Label;
Create a method in form one like this:
public void getLabel(Label label) {
Form2Label = label;
}
Then, when you click the button in Form1 just add a bit of extra code.
Form2Label.Text = this.TextBox.Text;
Now when you start Form2, run the method, and pass it the label.
Form1.getLabel(this.label);
That should work. You'd have to try it out.
|
|
|
|
|
Try using this way
declare a bool variable in form2 with public accessiblity
like
<br />
public bool clicked;<br />
and in the form load event you can check like
<br />
if (clicked)<br />
{<br />
}<br />
in form1's button1's click event write
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
Form2 frm = new Form2();<br />
frm.clicked = true;<br />
frm.Show();<br />
}<br />
Paras Kaneriya The difference between genius and stupidity is that genius has its limits.
|
|
|
|
|
|
Use XPath. In particular the XmlDocument.SelectSingleNode(...) function.
|
|
|
|
|
:(Its not working.....
stil it showing error
System.Xml.XmlException: The tag from namespace is not expected. Line 3, position 2. at System.Xml.XmlReader.ReadElementString(String name) at ElsBook.First.Button1_Click(Object sender, EventArgs e)
If we give multiple number of read stmt, its working
|
|
|
|
|
try this
XmlDocument xmldoc = new XmlDocument();
FileStream fs = new FileStream(Xmlfilepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
xmldoc.Load(fs);
XmlNodeList xmlnode = xmldoc.GetElementsByTagName("ABC");
for (int a = 0; a < xmlnode.Count; a++)
{
if (xmlnode[a].Attributes[0].Value == "requirednode")
{
}
}
Becoming Programmer...
|
|
|
|
|
Still some error......
Inside for loop.....
|
|
|
|
|
It would help everyone if you could provide a sample of the XML (even a subset would be good) and information about the error you are encountering. Saying you've run into an error leaves things up to a lot of interpretation.
[modification]And sample code showing how you are trying to read the file and go to the specific node would be helpful as well.[/modification]
|
|
|
|
|
This is the xml
<?xml version="1.0" encoding="UTF-8" ?>
<family>
<name gender="male">
<firstname>Tom</firstname>
<lastname>Smith</lastname>
</name>
</family>
and the code is --------
FileStream fs = new FileStream("D:\\Myfolder\\gender.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
xmldoc.Load(fs);
XmlNodeList xmlnode = xmldoc.GetElementsByTagName("name");
for (int a = 0; a < xmlnode.Count; a++)
{
if (xmlnode[a].Attributes[0].Value == "gender")
// match your attributes
{ //codes
lblcnt.Text=a.ToString();
String firstNameValue = reader.ReadElementString("gender");
Lblmsg.Text=" FirstName: "+firstNameValue;
}
I tried this one also=======
XmlTextReader reader = new XmlTextReader ("D:\\Myfolder\\gender.xml");
XmlDocument xmldoc = new XmlDocument();
XmlTextReader reader = new XmlTextReader ("C:\\gender.xml");
try
{
while (!reader.EOF)
{
reader.Read();
if(reader.IsStartElement() )
{
reader.Read();
xmldoc.SelectSingleNode("family/name/firstname");
XmlNode xmlnode1=xmldoc.GetElementsByTagName("firstname");
String firstNameValue = reader.ReadElementString("firstname");
xmldoc.SelectSingleNode("lastname");
String lastNameValue = reader.ReadElementString("lastname");
Lblmsg.Text=" FirstName: "+firstNameValue + " LastName: " + lastNameValue;
}
}
reader.Close();
}
catch (Exception err )
{
Lblmsg.Text="Error: " + err.ToString();
}
-- modified at 23:06 Wednesday 12th September, 2007
|
|
|
|
|
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?
|
|
|
|
|
Hi,
What is the Type of SchoolID? I am assuming it is "int" then you can try to write this line;
List.Add((int)SchoolDT.Rows[cboSchool.SelectedIndex]["SchoolID"],cboSchool.Text.ToString());
Mert Kantarcıoğlu
|
|
|
|
|
|
try reading these
1[^]
2[^]
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
If the 'TabAlignment' of a 'tabControl' is set to 'Left', the Controls headers text is aligned vertical.
Can anybody please introduce me to a way to realign (or rotate) the tabs header text so its displayed horizontal, while the headers still are on the left of the control?
Thanks in advance
-Soo
|
|
|
|
|
|
My question is actually in the subject. I'm tring to stop execution of code until webbrowser reloads the page, but the point is that most of it is coming in the background using AJAX httprequests so browser's DocumentCompleted event is raised to early while most of the document is still on the flight. How can I achieve the same effect as in mentioned event when AJAX stuff needs to be taken into consideration? should i monitor for net requests and responses coming in and out? it seems really complicated. Anybody has some idea?
|
|
|
|
|
completely no ideas? for now i made a timer but it assumes that quality of a connection is fine and has a constant interval which is not good and fails sometimes ..
|
|
|
|
|
When declaring:
[DllImport("kernel32.dll")]
public static extern int OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
It dosnt seem to matter what argument datatypes you use, for instance, this works aswell:
[DllImport("kernel32.dll")]
public static extern UInt32 OpenProcess(uint dwDesiredAccess, uint bInheritHandle, Int32 dwProcessId);
Question 1:
What should you think of when declaring imported functions? Should you try to match the c/c++ datatype to its c# datatype couterpart? (For instance, for c++ int, c# Int32). Or does it not matter?
Question 2:
Arguments that are pointers. I dont quite understand how IntPtr etc works since im quite new to c#. But if a function has a parameter that is a pointer (int* return_val for instance. Should you use a IntPtr for that? Or an unsafe c# pointer?
Question 3:
Arguments that are typedef'ed types, for instance handles that are a c++ (void*). Should you use c# unsafe void*? Or is an int just as fine? Are there any rules for this? For instance, HWND is a UInt32 or something like that..
Question 4:
The "out" parameter, should it be used for c++ pointers and references that returns values (non const)?
Thanks.
|
|
|
|
|
Others might give you a more complete answer, but I usually end up here[^] for interop stuff.
"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.
|
|
|
|
|
Hi,
Q1.
parameter type does not have to be exact, so you can e.g. mix int, uint, Int32 (anything
that is a 32-bit integer). Be careful with long (64-bit in C#, 32-bit in native C), and
use some int type when native is bool.
Q2.
pointers to basic types (such as int*) just need a ref keyword
read-only string is just string
writeable string buffer is StringBuilder with sufficient initial capacity
pointers to a composite type are more complex; either:
- specify the correct type and hope the default marshalling will work correctly for you;
- specify the correct type and add marshalling attributes as appropriate (complex stuff!);
- or specify an IntPtr, but then all you get is the pointer value, so you still must solve
the marshalling; typically you would use Marshal.PtrToStructure, PtrToStringAnsi, etc.
Warning: IntPtr is 4B or 8B depending on OS; you must use IntPtr for all Windows handles.
Q3.
I never use unsafe or void*. I prefer to use same things as in Q2.
Q4.
Use out or ref keyword for value types (int, struct) that need a pointer so the native
code can change the value.
In general, if you are in charge of both sides, keep the interface simple; I prefer to:
- work with ints and strings, occasionally a struct containing ints;
- avoid structs/classes containing other classes (including strings);
- allocate memory in managed code, not have native code create stuff and return a pointer.
Warning: if you must pass a pointer from managed to unmanaged and the marshalling does not
make clear it is a pointer (it would know with string, StringBuilder, etc. but not with
IntPtr), then you must use the GCHandle class and pin the object.
Final comment: I tend to experiment with P/Invoke and put a lot of logging statements
at both managed and unmanaged sides (the first function I implement is logging a string
from unmanaged to managed world, so I can collect and display (Console.WriteLine, ListBox...)
logging from both sides on the managed side. That way you can easily see where things start
to go wrong.(This takes a delegate as a function pointer, you did not ask that yet!).
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
|
|
|
|
|
Hi all,
we have a table in sql server database.
We are using a data grid view control in our c# application.
How to retrieve and display a single record from the data base into the data grid view control.
Please suggest us at the earliest.
Regards,
Priya
|
|
|
|