|
|
Hi all. How i can make control reflect changes was maded on his datasource?
<br />
ctlTextEdit.DataBindings.Add(new Binding("EditValue", _mySourceDataRow, "Field1"));<br />
<br />
....<br />
<br />
void someButton_onClick(...)<br />
{<br />
_mySourceDataRow.Field1 = "New text";<br />
<br />
} <br />
<br />
Or exists an method in Form class what make all child controls reread values from ones data sources?
THANK.
|
|
|
|
|
|
I'm looking for more efficient Xml reading. I do not mean performance - I load small files. I'd rather ask about coding style/methods. Now I use the following routine:
public static void FromFile(string path, KorepetytorMenu menu)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(path);
foreach (XmlNode rootNode in xmlDoc.ChildNodes) {
XmlElement rootEl = rootNode as XmlElement;
if (rootEl != null && rootEl.Name == "KorepetytorMenu") {
foreach (XmlNode node in rootEl.ChildNodes) {
XmlElement el = node as XmlElement;
if (el != null && el.Name == "RootNode") {
menu.rootNode = KorepetytorMenuNode.FromXmlElement(el);
ReadNodeChildsRecursive(menu.rootNode, el);
}
}
}
}
}
I just have been starting coding this, but I wrote some programs like this in the past and I know that it gets annoying when there are 10 or more nested foreach'es an if's.
A sample Xml file:
<?xml version="1.0" encoding="utf-8" ?>
<KorepetytorMenu>
<RootNode Header="" Image="">
<Node Header="Fizyka">
<Node Header="Równania Rózniczkowe" Image="Gwiazdka.png" />
<Node Header="Kinematyka 1" File="Matma\Równania Rózniczkowe.xml" />
(...)
</Node>
</RootNode>
</KorepetytorMenu>
Any ideas?
Thanks in advance.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Just note: I do NOT want to use reflection to perform this task, because the first use of reflection causes a slow-down, so if I need it to show main menu, then... . I tried to use Xml Serialization system in .Net, but I didn't like it. It's too slow (as it uses reflection) and forces me to design class in a specific style which does not satisfy me. Cheers!
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Take a look at XPath and the Node.selectNodes(...) method
led mike
|
|
|
|
|
Ok I get it. Thanks.
public static void FromFile(string path, KorepetytorMenu menu)
{
XPathDocument doc = new System.Xml.XPath.XPathDocument(path);
XPathNavigator nav = doc.CreateNavigator();
if (!nav.MoveToChild("KorepetytorMenu", "")) return;
if (!nav.MoveToChild("RootNode", "")) return;
menu.rootNode = KorepetytorMenuNode.FromXmlNavigator(nav);
ReadNodeChildsRecursive(menu.rootNode, nav);
}
Is it a correct approach?
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
gajatko wrote: Is it a correct approach?
Well I'm not sure what you are trying to do and that is certainly an improvement, but you still have not used XPath. If you want to access a possible set of elements you can use XmlNode.SelectNodes with an XPath statement and it is possible to get a collection of all the nodes you are interested in and then you simply iterate the list and do whatever operations you need for each XmlNode in the collection. See the example code in the documentation for XmlNode.SelectNodes()
led mike
|
|
|
|
|
Do you think of sth like this?:
static void ReadNodeChildsRecursive(KorepetytorMenuNode rootNode, XPathNavigator nav)
{
XPathNodeIterator iter = nav.SelectChildren(XPathNodeType.Element);
while (iter.MoveNext()) {
if (iter.Current.Name == "Node") {
rootNode.Nodes.Add(KorepetytorMenuNode.FromXmlNavigator(iter.Current));
ReadNodeChildsRecursive(rootNode.Nodes[rootNode.Nodes.Count - 1], iter.Current);
}
}
}
And...
public static KorepetytorMenuNode FromXmlNavigator(XPathNavigator nav)
{
return new KorepetytorMenuNode() {
File = nav.GetAttribute("File", "") ?? "",
Header = nav.GetAttribute("Header", "") ?? "",
Image = nav.GetAttribute("Image", "") ?? ""
};
}
Maybe I should post it in my previous message so it would be clear what did I do.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Why don't you do it the easy way:
string myFileName = @"C:\test\my.xml";
DataTable data = new DataTable();
data.ReadXml(myFileName);
After you've done that, you can just retrieve the data from data.Rows...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
What about a situation when I have many meaningfull attributes and xml represents a tree with unbounded complexity? I though that a DataTable doesn't support more than a finite number of sub-trees, does it? Maybe I missed something, however.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
You could try it and see what happens. That's part of the adventure of being a programmer.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi !,
I am new to C# and was wondering if the standard components included in .NET are usefull enough to build winforms ? Or better buy 3rd class libraries ?
Thanks you !
Best regards,
Steve
|
|
|
|
|
with standard controls, you can develope any application, however nearly all third party controls are for good looking GUI they may slow performance too
and for more info, just google
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Steve Declerck,
Well, what do you want to do?, If its just simple form that inputs values into a DB, then sure, they are fine. If you want to display models and graphs, then, you'll need to buy some 3rd party libs.
Regards,
Gareth.
|
|
|
|
|
Hi Steve,
The standard .Net components are used to create WinFrom applications. However, it depends on your requirements or scope of your application. If .Net standard components meets your application's requirements then you can use them in your application in case if not then you may try ComponentOne's Studio Enterprise suite and evaluate it and see if those components can meet your requirements. Below is the link for the download.
http://download.componentone.com/pub/Net/c1studionet/Updates/C1StudioNET2_T307_Setup.exe[^]
For more information please visit www.componentone.com
I hope this helps .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
Controversial one here, but why develop in WinForms? Take a look at WPF - done properly you can change the look of the app later on. See this[^] post by the WPF meister Josh Smith.
|
|
|
|
|
Hello folks,
Many thanks for the replies, very helpful. Indeed it's for application that inserts data in a DB. I will try the standard components !
Thanks,
Steve
|
|
|
|
|
I'm coding an FTP client in C#, and I'm trying to use System.Net.Socket's BeginReceive method to stop the UI from freezing when receiving data. At present, it works as it should, but whenever there's a transfer in progress (upload/download or directory listing), the UI freezes until it's complete.
I want to use BeginReceive to recive data in a different thread. This is what I have to far:
Two classes - FTP and FrmMain.
In FTP I have a delegate:
<br />
public delegate void DirListDelegate(object sender, ArrayList items);<br />
public event DirListDelegate OnDirListComplete;<br />
The I have three methods:
<br />
private void OnDataReceived(IAsyncResult asyn) {<br />
int bytes = dataSocket.EndReceive(asyn);<br />
bldBuffer.Append(Encoding.ASCII.GetString(buffer, 0, bytes));<br />
if(bytes < buffer.Length) {<br />
dataSocket.Close();<br />
OnDirListComplete(this, itemsList);<br />
} else {<br />
WaitForData();<br />
}<br />
}<br />
private void WaitForData() {<br />
dataSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(OnDataReceived), null);<br />
}<br />
public void ListDir() {<br />
dataSocket = openSocket();<br />
<br />
bldBuffer.Remove(0, bldBuffer.Length);<br />
WaitForData();<br />
}<br />
Then I call FTP.ListDir() from FrmMain. What should happen is the main program should be free to respond to user clicks etc and not freeze, but it's as though I'm just using Receive instead of BeginReceive.
I'm really stuck on this and I'd appreciate any help.
|
|
|
|
|
Echilon wrote: I'm really stuck on this and I'd appreciate any help.
Hello Echilon and welcome to code project. You posted this problem yesterday and I replied to you. Now you start a new thread of the same subject without ever responding to my reply. That is considered rude and an abuse of the CodeProject resources.
Take a moment to read these posting guidelines[^] along with the first post in this forum titled "How to get an answer to your question".
led mike
|
|
|
|
|
So, the first attempt ended up in the wrong board, so I'm asking again here (hopefully the right board):
I'd like to add an existing Webusercontrol (.ascx) programatically to a class which returns a Webcontrol:
public class ClassName :IHoldtheDefinition
private WebControl AddName()
{
WebControl cntrl = new WbControl();
cntrl.Controls.Add(new Label() {Text="test"});
wuc_anything wuc = new wuc_anything(); //existing Webusercontrol inside the Assembly
cntrl.Controls.Add(wuc);
return wuc;
}
It doesn't throw an exception, but the content is not displayed.
Why I need it this way? I get the class just by it's name (implements an interface) and want to give the possibility to add content to a page by three simple steps.
1. Add the button definition to a xmlfile
2. add a class witch is named as defined in the xml file - the class has to implement the interface and returns a Webcontrol
3. If needed design a WebUserControl and add it programatically to the class as described above.
Help would be apreciated.
|
|
|
|
|
ezazazel wrote: So, the first attempt ended up in the wrong board, so I'm asking again here (hopefully the right board):
Never mind. Albeit it is an ASP.NET question but it figures under C#, the one thing to appreciate is your immediate response by posting it in a more near forum.
A few quick clarifications regarding your snippet:
ezazazel wrote: AddName
If you are invoking through an ASPX page through <% %> function, the exception might just get swallowed. Did you try encompassing the code in a try-catch and from within a CodeBehind. An attached debugger can help you flag out if control has any issues trying to enter the catch block.
ezazazel wrote: IHoldtheDefinition
Were there any warnings thrown during compilation regarding this?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
I think I located the problem. It seems to be here:
WebControl cntrl = new WebControl
(HtmlTextWriterTag.Div);<---
I tried HtmlTextWriterTag.Object /Unknown and many more.. sometimes I get a blank square, but most of the time nothing.
With the debugger taken a closer look, it reveals to me, that the control is correctly added. It is simply not shown (rendered).
WebUserControl1 wuc = new WebUserControl1();
cntrl.Controls.Add(wuc);
return cntrl;
Here the very essential part of the code, where WebUserControl1 holds a Label:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AddCntrlCls cls = new AddCntrlCls();
try
{
this.Controls.Add(cls.AddElement());
}
catch(Exception ex)
{
throw new Exception(ex.ToString());
}
}
}
public class AddCntrlCls
{
public WebControl AddElement()
{
WebControl cntrl = new WebControl(HtmlTextWriterTag.Div);
WebUserControl1 wuc = new WebUserControl1();
cntrl.Controls.Add(wuc);
return cntrl;
}
}
Yes, before I forget - I'm working with a project (WebApplication), therefore I can create instances of Controls, at least to me it ssems so.
|
|
|
|
|
Ah, I finally found a way. Thought too much in C# and not enough in ASP.NET
Here's the way it works:
public class AddCntrlCls : System.Web.UI.Page //Has to inherit from Page
{
public WebControl AddElement()
{
WebControl cntrl = new WebControl(HtmlTextWriterTag.Div);
cntrl.Controls.Add((Control)Page.LoadControl("WebUserControl1.ascx")); //Here is the Magic
cntrl.Controls.Add(new Label() { Text = "I'm a Text" });
return cntrl;
}
}
|
|
|
|
|
i'm working with SQL Server 2005
in my c# App i've got a DataGridView that is bound to a Source(a table in the database)
i can add new row ,delete row but CAN'T Update row Content
this is the code :
this is the event when a buttoncell is clicekd
<br />
private void dgvCarDetails_CellContentClick(object sender, DataGridViewCellEventArgs e)<br />
{<br />
switch (e.ColumnIndex)<br />
{<br />
case 8:<br />
UpdateDataSet();<br />
break;<br />
case 9:<br />
dS_CarManager.T_CarDetails.Rows[e.RowIndex].Delete();<br />
UpdateDataSet();<br />
break;<br />
}<br />
}<br />
<br />
this functions operate as a service function to update<br />
private void UpdateDataSet()<br />
{<br />
TA_CarDetails.Update(dS_CarManager.T_CarDetails);<br />
dS_CarManager.T_CarDetails.AcceptChanges();<br />
}<br />
<br />
<br />
<br />
<br />
Have Fun
Never forget it
|
|
|
|