|
Its not a dumb question at all because the answer isn't obvious.
In the Foo class there are two different implementations of Clone(), one which is a member of the class and the other is Foo's implementation of ICloneable.
Interfaces in C# (and .NET) require that their members be public; so when I specifically implemented the Clone method as Foo's implementation of ICloneable I didn't need to specify the public access modifier.
In C# there are two different ways to implement an interface.
The first method is by adding a public member for each item in the interface you are implementing. Most people probably use this technique to implement an interface.
interface IBar
{
object Bar();
}
class Foo : IBar
{
....
public object Bar()
{
....
}
} The second method is to specify in the member's signature what interface it is implementing.
class Baz : IBar
{
...
object IBar.Bar()
{
....
}
} Unlike the first method the only way to use this member is cast the object to the interface (IBar ib = (IBar) myBaz; ). Now you can use the member as if it were any other interface.
This also gives an advantage for the users of your class. You can provide two different implementations of a member: one to be used when dealing with the interface, the other to be used when dealing with the class itself.
Most of the collections in the .NET class library do this to provide a strongly-typed collection while also implementing the generic interfaces that provide a standard way of using a collection.
Hope that answers your question
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
I am trying to read a custom config section but its not working. ConfigurationSetting.GetConfig() returns null;
CONFIG FILE:
<configuration>
<configSections>
<section name="data" type="System.Configuration.SingleTagSectionHandler"/>
</configSections>
<data Server="GODSWORKSTATION" Username="MedWizard" Password="MedWizard" Security="SSPI"
PersistSecurity="false" Pooling="false" MinPool="20" MaxPool="1000" NetworkLibrary="dbmssocn"/>
</configuration>
CODE:
IDictionary valueTable = (IDictionary)ConfigurationSettings.GetConfig("data");
string Server = (string)valueTable["Server"];
string Username = (string)valueTable["Username"];
string Password = (string)valueTable["Password"];
string Encrypt = (string)valueTable["Encrypt"];
string Security = (string)valueTable["Security"];
Any ideas? Thanks.
Steve
Not all who wander are lost...
|
|
|
|
|
You need to change the section line to specify the full assembly name (since the assembly has a strong name this means the typename, the assembly name, version, and public key token).
<section name="data" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
I have an article that's done but needs formatting and proofreading before I post it.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
|
Oops
it should have been configurationhandler not section
Correct link[^]
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
I have a c# project that is causing me problems at the moment.
I have a file that looks like this
------------
using System ;
namespace MyNameSpace.System
{
public class Test
{
public Test ()
{
System.Diagnostics.Trace.Writeline ("Hello World!") ;
}
}
}
------------
the problem is that when I compile this it VS complains that the namespace Diagnostics does not exist in MyNameSpace.System
Also when I type System. the intelisense gives me a choice of 'Test' only i.e. my clases in the MyNameSpace.System namespace.
if I change the line to
Diagnostics.Trace.Writeline ("Hello World!")
dropping the System it all compiles.
Is this normal namespace behaviour? If not (hope not as this sucks) anyone got any idea on how to fix it?
Thanks
Stephen.
|
|
|
|
|
Stephen Woolhead wrote:
Is this normal namespace behaviour?
Yep. Perhaps Eric can explain it better (I just spent 10 minutes trying to and couldn't get it out right) but IIRC namespaces are evaluated from right to left, so the System matches before it gets to the root System namespace; however Diagnostics doesn't match until it gets to the root System namespace.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Just seemed strange to me that as I was in the namespace MyNameSpace.System and had a using statement for System when I was used System.Diagnostics, that it should resolve to MyNameSpace.System.Diagnostics instead of trying the following
MyNameSpace.System.System.Diagnostics (Current namespace)
System.System.Diagnostics (Using System Statement)
System.Diagnostics (using the global namespace)
Of which the last one would have been resolved.
Is there a way to say that this is the start of the namespace do not append to anything, something like ::System in C++ ?
Thanks
Stephen
|
|
|
|
|
Stephen Woolhead wrote:
Just seemed strange to me
It does to me too; perhaps this will be addressed in the future (so that it tries all the way up instead of stopping at the first failure -- MyNameSpace.System.Diagnostics)
Stephen Woolhead wrote:
Is there a way to say that this is the start of the namespace do not append to anything
Not that I know of, I think something is needed at any rate.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Stephen Woolhead wrote:
Is there a way to say that this is the start of the namespace do not append to anything, something like ::System in C++ ?
No but you can try this code example. It's an almost solution to the problem.
using System;
using WinSystem=System;
namespace Test.System {
public class Test {
public static void Main(String[] args) {
WinSystem.Console.WriteLine("Hello World");
}
}
}
Jared
jparsons@jparsons.org
www.prism.gatech.edu/~gte477n
|
|
|
|
|
Hi everybody!
I have the following code in the constructor:
lstUsers = new ListView();<br />
lstUsers.Parent = this;<br />
lstUsers.Location = new Point(0, panelTitle.Height);<br />
lstUsers.Size = new Size(Width, Height - lstUsers.Location.Y + 1);<br />
lstUsers.Anchor = AnchorStyles.Left | AnchorStyles.Top |<br />
AnchorStyles.Right | AnchorStyles.Bottom;<br />
lstUsers.View = View.Details;<br />
<br />
lstUsers.Columns.Add("Clave", 150, HorizontalAlignment.Left);<br />
lstUsers.Columns.Add("Nombre", 250, HorizontalAlignment.Left);<br />
lstUsers.Columns.Add("Permisos", 100, HorizontalAlignment.Right);<br />
The list view appears ok, and when I add items, I can see them in large icon mode (if I remove the View = Details), but in Details mode I don't see anything... not even the column headers (after adding the columns I verified and Columns.Items.Count is indeed 3)
Any ideas???
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Hi, try adding
listUsers.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
or Clickable.
Hope this helps
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Sorry, it didn't work
The only one that seemed to have an effect was ColumnHeaderStyle.None, which removed the place where columns are supposed to appear.
Thanks anyway,
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Luis Alonso Ramos wrote:
The list view appears ok, and when I add items, I can see them in large icon mode (if I remove the View = Details), but in Details mode I don't see anything...
How are u adding the ListViewItems? If u want to see "multi-columns" make sure it looks like this.
listUser.Items.Add( new ListViewItem( new string[] {"col1itemtext","col2itemtext","col3itemtext"}));
and NOT:
listUser.Items.Add( "colitemtext")
Are u not maybe overwriting the columnheaders?
Hope this helps
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Hello,
<br />
while(oReader.Read())<br />
{<br />
ListViewItem lvi = new ListViewItem();<br />
<br />
lvi.Text = (string) oReader.GetValue(oReader.GetOrdinal("LoginName"));<br />
lvi.SubItems.Add((string) oReader.GetValue(oReader.GetOrdinal("Name")));<br />
lvi.Tag = (int) oReader.GetValue(oReader.GetOrdinal("ID_user"));<br />
<br />
lstUsers.Items.Add(lvi);<br />
}<br />
This is what I'm using... If I set another view (View.List) for example, the items show OK. It's just the details view that I'm having trouble with.
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Hehe, from what i can see u dont seem to have VS.NET. In the collection editor u can see (and i had a problem here at 1st too ) how the displayed data is laid out. The ListViewItem is also the 1st SubItem. Try this (i asumme an OleDbReader??)
string[] str_arr = new string[3];
str_arr[0] = (string) oReader.GetValue(oReader.GetOrdinal("LoginName"));
str_arr[1] = (string) oReader.GetValue(oReader.GetOrdinal("Name"));
str_arr[2] = oReader.GetValue(oReader.GetOrdinal("ID_user")).ToString();
lstUsers.Items.Add(new ListViewItem( str_arr));
This is a bit tedious though. I would normally create a LVI property on a class needed to be displayed in detail. Then all i do is use the following constructor for my ListViewItem (from MSDN):
Initializes a new instance of the ListViewItem class with an array of strings representing subitems.
public ListViewItem(string[]);
Hope this gets you going
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
from what i can see u dont seem to have VS.NET
Yes, I'm using Visual C# .NET. But I'm typing most code manually.
The problem is not adding the items, those are added correctly (I can see them as expected in other Views). What I'm having trouble with is adding the columns. In another form I use a list view also and everything works OK. I copied that exact same code to this panel (it's a Panel control, but the one that works is on a TabPage which is also a Panel) and same problem, no columns show up.
I'll give it a try to your way of adding items, but I don't think that will solve it.
Thanks!
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
I fixed this problem!!!
The problem was I was calling lstView.Clear() and that removes all items AND columns. I now call lstView.Items.Clear() and everything works as it should!
Thanks everyone for your help!
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Hi,
I need to know, if the tab-key is pressed in a single-line textbox. But if any control in the form has the TabStop-property set to true, there will no event be raised before leaving the control. The only event raised is the KeyUp event of the form, if the KeyPreview is set to true. But when it is raised, the focus is already in the next control.
Does someone know a way to check, if the tab-key is pressed? I thought I could work with the Leave-event, but I don't know, if the control will be left because of the tab-key.
Thank you for your help,
Michael
muenchen-michi@gmx.de
|
|
|
|
|
I'm not sure, but there is an AcceptTab property (and AcceptReturn too, I don't know if it only applies to multiline)... you could try setting that to true and handling KeyDown/KeyUp/KeyPress... then you call SelectNextControl to move the foucs to the next control in the tab order.
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Hi Luis,
thanks for you answer. But these properties only apply to multiline textboxes. So this won't help me.
Michael
muenchen-michi@gmx.de
|
|
|
|
|
Why would you like to trap the tab key? to be able to prevent the user from tabbing away from your control?? what for? maybe we can find another solution.
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Hi all
Has anyone a clue how to do or approach this?
If you dont know what I mean, open Word and select some text and click the Highlight Button
Thanking all in advance
Cheers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I think that the only way you're going to be able to do this is if you add the code with the rich text format codes applied. You will have to get the text from the box via Rtf. This will give you the text of the box with all of the format codes applied. You can then manually edit it and put in the format codes that you want. However this is a very large pain in the ass.
Jared
jparsons@jparsons.org
www.prism.gatech.edu/~gte477n
|
|
|
|
|
Thx
But SelectedRtf (and Rtf) from a RichTextBox seems to be very picky. I was try just to copy SelectedRtf from one RichTextBox to another and 9/10 times exceptions was thrown.
I will try it though. Maybe it was escaping or something.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|