|
I definitely want to learn... do you know any good resources/tutorials on delegates/events. I have read through c# Unleashed and Windows Forms Programming in c#, but still am struggling to comprehend. Perhaps I am over analyzing this...
I will continue to read up on it.
|
|
|
|
|
This not MS way (they use EventArgs as the base) but here is a short snippet from one of my early project that may lead you in the right direction.
#namespace TabCode
{
public class TabChoice
{
public string Text;
public bool Active;
public TabChoice(string text, bool active)
{
Text = text;
Active = active;
}
}
public delegate void TabPanelChangeEvent(TabChoice choice);
public class TabPanel : Panel
{
private ArrayList _choices;
public TabPanelChangeEvent Change = null;
private void FireChange(int index)
{
if (Change != null)
{
Change((TabChoice)_choices[index]);
}
}
}
}
|
|
|
|
|
Thanks,
I was able to build a working delegate, the problem is I still have to instantiate a new copy of the form. I need to use the already instanciated copy of it because it has parameters and values that I need to use.
Any other thoughts??
|
|
|
|
|
Why don't you just tell the UserControl the parameters. If they change, update the UserControl.
I am not clear on what you are attempting to do but, creating a new copy of the form does not seem like a proper solution.
|
|
|
|
|
OK... my form loads a usercontrol that has a list of radiobuttons. This is not a modal form as they are always available for clicking. A command button on that form launches code on the main form. I have to know what radio button was selected and pass that back to the main form.
Here is the code so far:
In usercontrol:
public delegate void delRunStep(string name);
private void cmdRunStep_Click(object sender, System.EventArgs e)
{
//find out what radiobutton is selected
MainForm mf = new MainForm();
//This does not work as it makes new Mainform and looses all Data.
delRunStep run = new delRunStep(mf.RunStep);
run(myString);
}
In the main form:
public void RunStep(string StepName)
{
//do code
}
|
|
|
|
|
Why does the UserControl need to know what radio button is selected on the main form? Could it not just pass back that the command button was clicked and let the main form decide what to do with the information?
Otherwise:
If the UserControl has to be notified of the state of the radio buttons then let it listen.
public void RegistureRadioButton(RadioButton rb)
{
rb.CheckChanged += new EventHandler(OnCheckChange);
}
private void OnCheckChange(object sender, EventArgs ea)
{
RadioButton rb = (RadioButton)sender;
if (rb.Checked)
{
if (rb.Text == "Choice 1")
{
}
}
}
|
|
|
|
|
The Userform has the Radiobuttons. But what you are saying will work,if I switch it around and make the main form know what radiobutton is selected. I will keep on working on it. I think I have enough info to make it work.
Thanks.
|
|
|
|
|
It may be that I dont really get the problem but as Micheal already mentioned you could just pass the existing form to your user control. Give the usercontrol a property where the form can be set and than use this instance:
(within MainForm)
<br />
UserMenu menu = new UserMenu();<br />
menu.MyMainForm = this;<br />
This is probably the easiest way, but an event should be better. For that you have to decalre an event in UserMenu and consume it on the MainForm (just like you would handle the Click event of a Button).
|
|
|
|
|
I want to do it the best way. I added code in the above post. I do appreciate all the help.
|
|
|
|
|
I used the tutorial at http://www.codeproject.com/csharp/cpimpersonation1.asp to try to perform an impersonation.
The code seems to run fine, and when I execute it there must be some sort of sign on happening. The reason I say this is because when I actually do try to sign on with incorrect user name or password it does throw an exception (as it should).
Anyways, when the code goes to access some file off of a local computer that only my account should have access to, it doesn't work, and the program says it failed to open the file sucessfully. Any suggestions?
Cheers,
Jim
|
|
|
|
|
Anotehr wierd thing happens. When I execute the code, and then try saving a file (under the guise of my new user) it doesn't seem to work. Basically, it saves it under its old identity.
Any ideas?
|
|
|
|
|
Hello,
How can i perform a Fade / Swipe of objects in directX. I'm creating a NarrowCasting software that is like a powerpoint presentation.
I'm using Direct3D because DirectShow is decapricated.
Please could you help me,
Greetz
Squall Blade
|
|
|
|
|
I've got a network stream. I have it working both Synchronously, and Asynchronously. My problem is this. I'd like to serialise objects to it. Simple enough Synchronously, serialise at one end, deserialise at the other.
But i'm not entirely sure what's the best approach.
What are the benefits of each? I can't see an easy way to serealise something to an Asynchronous stream. I'd need to declare how many packets and of what size I am sending, before I begin the send, then i'd need to serialize to a memory stream before reading the packets into a buffer and sending them down the network stream. While at the same time, keeping track of what i've sent so far, and how much is left, as well as what other objects are queued to follow the current one. This strikes me as slow and inefficient.
The benefits of asynchronous network handling is the event handles and system thread that manages them, meaning I don't need to poll for pending data.
Ultiately, given these tradeoffs, what is the standard way of handling this situation in .net and C#? I'm leaning towards the simple serialization approach, but if i was say, sending a large file, it could clog up the network for a long time.
What do you advise?
Cheers
Cata
|
|
|
|
|
Is it considered good coding practice to use goto statements in c# ??
|
|
|
|
|
yes it make spaghetti code
that depend on flages
also it breake the block code conception
Aswanee
|
|
|
|
|
To convert the other posters answer into English...
No, it's not considered "good practice".
It breaks certain OOP standards and makes your code harder to read.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have DOTNET project that connect to excel through RTD. After some time say 2 week the excel lose the connection to RTD component
I will be thankful if any body guide me how to solve this problem or how to fiend the reason of it
And thank of all any way
Aswanee
|
|
|
|
|
Cross-posting acrossed multiple forums is considered very rude.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi
i unable to read an xml file, i write xml file successfully before facing any problem.
but when i want to read i unable to through, i saw lots of example of reading an xml file but
its read an element by specifying its value but
what if i do not know the value, i just want a dynamic interaction, that's it.
please help me out, it's urgent!!!!!!!!1
bhupendr singh
|
|
|
|
|
well you should use System.Xml.XmlDocument to load your xml e.g. doc.LoadXml(xmlString)
then you can do any of the following -
XmlNodeList nodeList = doc.DocumentElement.SelectNodes("//section");
this will select all nodes that are named and you can itterate through this XmlNodeList object.
System.Xml.XPath.XPathNavigator nav = doc.CreateNavigator();
probably better for you since you dont know the value then you can itterate through this object by calling its various methods e.g nav.MoveToNext();
|
|
|
|
|
my snippet of code look like this:
1.XmlDocument doc=new XmlDocument();
2.doc.LoadXml("c:\\bhupen\\bsdXml.xml");
3.string a=doc.ToString();
4.XPathNavigator nav=doc.CreateNavigator();
5.nav.MoveToFirstChild();
6.string b=nav.Value;
In this code i got an exception error:
An unhandled exception of type 'System.Xml.XmlException' occurred in system.xml.dll
Additional information: System error.
at line no. 2 means it unable to load xml.
other than this problem ref. line no. 6:
is this a proper way to reach sub element of the root element or
available any other suitable way.
please suggest.
Bhupendr Singh
|
|
|
|
|
ok
2. doc.loadXml only takes a string of xml you should use doc.load(filename)
3. a will contain a string value of the object name i.e. System.Document.XmlDocument if you want to get the xml in the file you should say string a = doc.innerXml
6. almost - string a = nav.current.value
|
|
|
|
|
Extract data and create xml for input
--------------------------------------------------------------------------------
Hi
I am given with a xml schema file.( with field name and datatype),
then along with a (*.unl file) with data's for the above schema file.
but without field names. each data is seperated by "|" character.
ie, like consider xml schema having field names as
Ex:
---
<xs:sequence>
<xs:element name="division" type="xs:int" minoccurs="0">
<xs:element name="location" type="xs:int" minoccurs="0">
<xs:element name="position" type="xs:string" minoccurs="0">
like this
and wheras (*.unl file) has values as follows
1|10|DAVID
1|10|JOHN
1|10|BECKER
...etc like so on.
Now what I have to do is that create a xml file along with schema and data's .
And later on use this xml file as input and have to create a report.
How to load these dta's intoa xml file for that particular schema.
how to program this.
pls help me to do this.
santhosh
|
|
|
|
|
|
I know subject sounds a bit odd but it's the most appropriate one I could come up with. After 1,5 year of c-sharping I cannot explain and solve my problem.
The thing is:
1. I'm working on my own inherited DataGrid class
2. I want to embed certain functionality in the grid (custom paging, sorting, filtering, etc.)
3. To ease programmatic creation of an instance of my control I introduced a collection class (AcidColumnCollection) of an object of AcidColumn type. This is really simple class which store information about the columns (if a column allows filtering, for instance).
4. The problem appears in ItemCreated method when I want to add a TextBox to the header cell (for filtering purposes). Have a look at this code snippet:
protected override void OnItemCreated(DataGridItemEventArgs e)
{
...
// insert glyphs in header cells for indication of order and texboxes
for(int i = 0; i < this.Columns.Count; i++)
{
// find a cell
TableCell tc = e.Item.Cells[i];
GenerateOrderInformation(tc, i);
GenerateFilterTextBoxes(tc, i);
}
...
}
Let's consider GenerateFilterTextBoxes method:
private void GenerateWhereTextBoxes(TableCell tc, int i)
{
string column = this.Columns[i].SortExpression;
// columns is an instance of AcidColumnCollection
// Filterable method checks whether a column which name is passed via this method's parameter should have a TextBox for filtering purposes.
if(columns.Filterable(column) == true)
{
// create controls to add
Label lblBreak = new Label();
TextBox txtBoxWhere = new TextBox();
// set properties
lblBreak.Text = " ";
// add them
tc.Controls.Add(lblBreak);
tc.Controls.Add(txtBoxWhere);
}
}
Basically I create AcidColumn object to store additional information about customised DataGrid columns. One of those is a property called Filterable. If it is true - a TextBox is added to that column. There no logic behind it so far, yet to be implemented. Simple as that.
What is the problem then? Well DataGrid events GO MAD - I click column 0 column 1 is sorted, I click column 2 - column 1 is sorted, I click on paging link, column 0 is sorted (!), the page is changed but the paging link does not change! It is really weird.
I made experiments and they ended in AcidColumnCollection.Filterable method. Look at this:
public bool Filterable(string p_name)
{
bool filterable = false;
foreach(AcidColumn col in this.List)
{
if(col.Name == p_name)
{
filterable = col.Filterable;
break;
}
}
return filterable;
}
ONLY if I use this collection method to examine filterable property and ONLY if I add TextBoxes to the datagrid header, the problem appears.
The last thing I did was replacing "return filterable" with "replace true" and... everything is FINE. PERF ECT. Change it back to filterable variable - the grid will not work.
Also if I use this Filterable method to check the property but DO NOT add any controls in GenerateWhereTextBoxes method - the grid beheaves normally.
I just do not know where the problem could lie. AcidColumn is a simple class. There's nothing behing Filterable property, nothing that could affect DataGrid events. And how come browsing through collection and checking its object properties in combination with adding controls to the grid generates such a strange problem!?
For your reference I'm enclosing Acid Column class:
public class AcidColumn
{
private string name;
private string type;
private bool filterable;
private int order;
public AcidColumn()
{
this.filterable = false;
}
public string Name
{
get { return name; }
set { name = value; }
}
public bool Filterable
{
get { return filterable ; }
set { filterable = value; }
}
}
Thanks for your advice,
Arek
|
|
|
|