|
Hi,
We are creating a C# Windows application using VS 2005.
It reads in an xml file and creates tab pages that each
have a datagrid that holds the specific information
for that tab's node.
We have been able to programmatically give the tab.text
(the label on the tabs), but when we try to add the
specific data for each tab into a datagrid on the
tab's page, all of the data gets added instead of the
data for just that node.
Perhaps we need to clear the grid first???
Any help would be appreciated.
Thank you in advance,
Anne
Here is a portion of the xml file we are using.
<?xml version="1.0" encoding="utf-8"?>
<inspection>
<inspforms>
<inspform>
<name>general</name>
<sections>
<section>
<tab>Heading</tab>
<label>
<name>id</name>
<type>text</type>
<value>
<single>200621</single>
</value>
</label>
<label>
<name>request
</name>
<type>text
</type>
<value>
<single>30
</single>
<choices>
<choice>
</choice>
</choices>
</value>
</label>
</section>
</sections>
</inspform>
<inspform>
<name>Risk</name>
<sections>
<section>
<tab>Operations</tab>
<label>
<name>Business Type</name>
<type>radio</type>
<value>
<choices>
<choice>
<choicename>Corporation</choicename>
<choicevalue>
</choicevalue>
</choice>
<choice>
<choicename>LLC</choicename>
<choicevalue>
</choicevalue>
</choice>
<choice>
<choicename> Partnership</choicename>
<choicevalue>
</choicevalue>
</choice>
<choice>
<choicename>Sole Proprietor</choicename>
<choicevalue>
</choicevalue>
</choice>
</choices>
</value>
</label>
<label>
<name>Years in Business</name>
<type>text</type>
<value>
<single>
</single>
</value>
</label>
</section>
</sections>
</inspform>
</inspforms>
</inspection>
Here is the pertinent code:
//frmMain.cs
<br />
using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Windows.Forms;<br />
<br />
using ABC.Components;<br />
using ABC.Globals;<br />
<br />
namespace ABC.Forms<br />
{<br />
public class frmMain : System.Windows.Forms.Form<br />
{<br />
public const string Path = @"C:\ABCXmls\abcBase.xml";<br />
public ArrayList ArrayListTabs;<br />
<br />
private ABC.Components.abcTabArea abcTabArea1;<br />
<br />
private System.ComponentModel.Container components = null;<br />
<br />
public frmMain()<br />
{<br />
<br />
XmlHelper.OpenFile(Path);<br />
ArrayListTabs = new ArrayList();<br />
ArrayListTabs = XmlHelper.GetArrayList("tab");<br />
InitializeComponent();<br />
}<br />
#region InitializeComponent()<br />
<br />
private void InitializeComponent()<br />
{<br />
...<br />
<br />
}<br />
#endregion<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new frmMain());<br />
}<br />
<br />
private void frmMain_Load(object sender, EventArgs e)<br />
{<br />
this.abcTabArea1.CreateTabs(this.ArrayListTabs, Path);<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
...<br />
}<br />
<br />
<br />
}<br />
}<br />
}<br />
//xmlHelper.cs
<br />
using System;<br />
using System.Collections;<br />
using System.Data;<br />
using System.IO;<br />
using System.Xml;<br />
<br />
<br />
namespace ABC.Globals<br />
{<br />
public class XmlHelper<br />
{<br />
private static XmlDocument XmlDocument1;<br />
<br />
public static void OpenFile(string path)<br />
{<br />
XmlDocument1 = new XmlDocument();<br />
XmlDocument1.PreserveWhitespace = false;<br />
XmlDocument1.Load(path);<br />
}<br />
public static ArrayList GetArrayList(string elementName)<br />
{<br />
ArrayList arrayList1 = new ArrayList();<br />
<br />
XmlNodeList xmlNodeList1 = XmlDocument1.GetElementsByTagName(elementName);<br />
<br />
for (int idx = 0; idx < xmlNodeList1.Count; idx++) <br />
{<br />
XmlElement xmlElement1 = (XmlElement) xmlNodeList1[idx];<br />
arrayList1.Add(xmlElement1.InnerText);<br />
}<br />
<br />
return arrayList1;<br />
}<br />
}<br />
}<br />
//abcTabArea.cs
<br />
using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Windows.Forms;<br />
<br />
namespace ABC.Components<br />
{<br />
public class abcTabArea : System.Windows.Forms.UserControl<br />
{<br />
internal TabControl TabControl1;<br />
internal string Path = "";<br />
<br />
<br />
private System.ComponentModel.Container components = null;<br />
<br />
public jmpBottom()<br />
{<br />
abcTabArea();<br />
}<br />
<br />
#region InitializeComponent()<br />
private void InitializeComponent()<br />
{<br />
...<br />
}<br />
#endregion<br />
<br />
public void CreateTabs(ArrayList arrayListTabNames1, string path)<br />
{<br />
this.Path = path;<br />
for (int idx = 0; idx < arrayListTabNames1.Count; idx++)<br />
{<br />
string tab = "";<br />
tab = arrayListTabNames1[idx].ToString();<br />
<br />
System.Windows.Forms.TabPage abcTabPage = new TabPage(tab);<br />
<br />
abcPage abcPage = new abcPage(tab,this.Path,idx);<br />
<br />
this.abcTabControl1.Controls.Add(abcTabPage);<br />
abcTabPage.Controls.Add(abcPage);<br />
<br />
}<br />
}<br />
<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
...<br />
}<br />
<br />
}<br />
}<br />
\\abcPage.cs
<br />
using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Windows.Forms;<br />
using System.Xml;<br />
<br />
<br />
namespace ABC.Components<br />
{<br />
<br />
public class abcPage : System.Windows.Forms.UserControl<br />
{<br />
internal string NodeName = "";<br />
internal string Path = "";<br />
internal int indexNum = 0;<br />
private System.Windows.Forms.Panel panel1;<br />
private System.Windows.Forms.DataGrid dataGrid1;<br />
private System.ComponentModel.Container components = null;<br />
<br />
public jmpPage(string nodeName, string path, int indexNum)<br />
{<br />
this.NodeName = nodeName;<br />
this.Path = path;<br />
this.indexNum = indexNum;<br />
InitializeComponent();<br />
Populate();<br />
}<br />
<br />
#region InitializeComponent()<br />
<br />
private void InitializeComponent()<br />
{<br />
this.panel1 = new System.Windows.Forms.Panel();<br />
this.dataGrid1 = new System.Windows.Forms.DataGrid();<br />
this.panel1.SuspendLayout();<br />
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();<br />
this.SuspendLayout();<br />
this.panel1.Controls.Add(this.dataGrid1);<br />
this.panel1.Location = new System.Drawing.Point(0, 0);<br />
this.panel1.Name = "panel1";<br />
this.panel1.Size = new System.Drawing.Size(800, 528);<br />
this.panel1.TabIndex = 0;<br />
this.dataGrid1.DataMember = "";<br />
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;<br />
this.dataGrid1.Location = new System.Drawing.Point(0, 0);<br />
this.dataGrid1.Name = "dataGrid1";<br />
this.dataGrid1.Size = new System.Drawing.Size(800, 528);<br />
this.dataGrid1.TabIndex = 0;<br />
this.Controls.Add(this.panel1);<br />
this.Size = new System.Drawing.Size(800, 528);<br />
this.panel1.ResumeLayout(false);<br />
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();<br />
this.ResumeLayout(false);<br />
<br />
}<br />
#endregion<br />
<br />
internal void Populate()<br />
{<br />
DataSet dataSet1 = new DataSet();<br />
XmlDocument XmlDocument1;<br />
XmlDocument1 = new XmlDocument();<br />
XmlDocument1.PreserveWhitespace = false;<br />
XmlDocument1.Load(this.Path);<br />
<br />
XmlNodeList xmlNodeList = XmlDocument1.GetElementsByTagName("section");<br />
<br />
XmlElement xmlElement1 = (XmlElement) xmlNodeList[this.indexNum];<br />
dataSet1.ReadXml(this.Path);<br />
dataGrid1.DataSource = dataSet1;<br />
dataGrid1.DataMember = "section";<br />
dataGrid1.CaptionText = dataGrid1.DataMember;<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
...<br />
}<br />
}<br />
}<br />
|
|
|
|
|
I have several labels stored in an array of label controls (Label[] drgLabel). The labels are placed in a panel control. I want to be able to move the labels around the panel using drag and drop technics. I do not know how to get the mouse_over event associated with the label because the labels do not have specific names. Do I have to write the mouse_over event for the array of labels (drgLabel)? Any suggestions will be greatly appreciated.
cbeasle1
|
|
|
|
|
You can bind the events in a loop:
foreach (Label label in drgLabel) {
label.MouseOver += new MouseEventHandler(drgLabel_MouseOver);
}
Which Label actually received the vent can be obtained from the sender. You surely have to cast this one:
private void drgLabel_MouseOver(object sender, MouseEventArgs mea) {
Label label = (Label)sender;
}
All events needed for drag and drop can be bound this way.
|
|
|
|
|
I have a program that was running really well on my computer. For sometime now, it has been running really slow and I find it hard to understand. I have scanned for viruses and spyware but couldn't find any and no possible reasons as the why the program is running that slow. Any suggestions? My computer specification is : pentium4, 3.40GH, 512MB
Nana
|
|
|
|
|
1) Is this the correct forum, is it a C# program?
2) Has your disk been defragged recently?
3) Do you have lots of services / background apps running?
Ed
|
|
|
|
|
It is a C# project i am working. I do not have lots of back apps running. This is because I am running below the physical memory. Yes it has been fragmented . Thank you.
Nana
|
|
|
|
|
Well, there could be thousands of reasons...
What kind of program is it? What does it do? Who made it? How slow is "really slow" really?
---
b { font-weight: normal; }
|
|
|
|
|
I am new to C#, and I have compiled a simple exe (a WindowsFormsApp, not a console app) to perform an operation, and want to notify the calling application when it has completed and return a status code.
ApplicationExit();
Just seems to exit, and even if I try to set a return code with:
System.Environment.ExitCode = #;
I don't seem to get anything either.
Can anyone help??
Thanks,
Mark
|
|
|
|
|
Hello,
Try the following
[STAThread]
static void Main()
{
Application.Run(new Login());
return 999;
}
In the retun, you get the exit code
/// -----------------------
Braulio Díez
http://www.bdiez.com
/// -----------------------
|
|
|
|
|
|
Doesn't have to be, valid types are void and int according to the C# spec I seem to remember, same as in ANSI C
Ed
|
|
|
|
|
|
Ravi Bhavnani wrote: Isn't Main() a void method?
Main() can be either void or int :
[STAThread]
static int Main(string[] args)
{
if (error)
return 1;
else
return 0;
}
-----
In the land of the blind, the one eyed man is king.
|
|
|
|
|
Ravi,
Yes, your code works perfectly. Thanks!
This code works also:
Application.Exit();
Environment.Exit(2445);
Thanks,
Mark
|
|
|
|
|
Thanks, but I think you meant to thank Braulio.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
|
Hi,
When loading a program how do i check if an instance of the same program is already runing, and if so maximizing it from the system tray instead of opening a new instance?
tnx
Roy
|
|
|
|
|
Search the articles here on Code Project. There are many that cover this topic.
www.troschuetz.de
|
|
|
|
|
Hi, I get a window crash on executing the following code. Problem tracked on sending the message RB_SIZETORECT. Please let me know if there is any solution for this and anybody faced same problem. Thanks ..
Win32Wrapper.RECT rbWindowRect = new Win32Wrapper.RECT();
Win32Wrapper.GetWindowRect(m_ReBarWindowHandle, out rbWindowRect);
int height = Win32Wrapper.SendMessage(
m_ReBarWindowHandle, Win32Wrapper.RB_GETROWHEIGHT, 0, 0);
Win32Wrapper.RECT insetRect = new Win32Wrapper.RECT();
insetRect.Left = rbWindowRect.Left;
insetRect.Top = rbWindowRect.Top;
insetRect.Right = rbWindowRect.Right;
insetRect.Bottom = (rbWindowRect.Top + height);
Win32Wrapper.SendMessage(
m_ReBarWindowHandle,
Win32Wrapper.RB_SIZETORECT,
0,
ref insetRect);
test test
|
|
|
|
|
Hello,
When you build a custom control and place it on the toolbar in the VS IDE, then add it to a form, the public properties are dynamically loaded for that control/class in the properties window, right? I want to replicate that functionality in a test application.
Basically I'm building a class library that serializes/deserializes classes into/from XML documents on a network stream (through a socket.) As the serialized objects come down the wire and are deserialized into objects, they are sent to the (Windows) UI through events. I want to store them into something like a ListView (using a derived class from ListViewItem that holds a reference to the object) then when I click on an item in the ListView, a properties window is displayed showing all the public properties of that object along with the values. Then I can make sure that the objects are being serialized/deserialized correctly.
Any ideas how would I do this?
Thanks
|
|
|
|
|
You can achieve this by using reflection. The following lines of code should point you in the right direction.
PropertyInfo[] propertyInfos = obj.GetType().GetProperties();
for (int index = 0; index < propertyInfos.Length; index++)
{
propertyInfos[index].Name;
propertyInfos[index].GetValue(obj);
}
www.troschuetz.de
|
|
|
|
|
That't great! Thank you very much
|
|
|
|
|
You can use a propertygrid to display the properties of the class.
You can make changes to the object through the propertygrid though.
|
|
|
|
|
I have an alarm application for a Pocket PC (DELL Axim x51). When the alarm ring I play a beep sound using soundplayer class's PlayLooping method. But the sound stops on touch of any part of screen. I should play the sound until the user hits the STOP/SNOOZE menu buttons(which I have in my application). I display a messagebox when it starts playing. please suggest me how to keep the sound playing until the user hits my menu buttons. I do stop it in menu's event handler but before that when the user clicks on the screen it stops. I need to prevent this from happening and should make the sound stop only on click of my menu items.
--Shobha
-- modified at 10:56 Monday 3rd April, 2006
I have forgot to mention that I'm using OPENNETCF's Soundplayer class and my project is on Visual Studio.NET 2003.
|
|
|
|
|
Hi
I got an .png Image and want to convert it in an .gif file. When i try to show the .png file in an img tag the backround color of the image is grey. I heard Inetrnet Explorer can't show transparent .png files.
So i want to convert it in an .gif file. But after that the background of my .gif file is black..
<br />
String gifFilePath2 = System.IO.Path.Combine(path, fileName + "_scaled.png");<br />
String gifFilePath3 = System.IO.Path.Combine(path, fileName + "_scaled.gif");<br />
<br />
System.Drawing.Image imgGIF = System.Drawing.Image.FromFile(gifFilePath2);<br />
Bitmap bmpGIF = new Bitmap(imgGIF, size);<br />
bmpGIF.Save(gifFilePath3, System.Drawing.Imaging.ImageFormat.Gif);<br />
|
|
|
|