|
led mike, thanks for the lead - I didn't think it would be as part of each column's properties. my fault, thanks for the help!!
- joe
|
|
|
|
|
Hello experts
i would like to know how to delete a row from a dataGrid (which is in edit mode), i am using paging and the built in edit, update, cancel methods.
I have been looking all over the posts most seem to be using databases and since i am using a XML file as my surce of data i am abit lost.
heres what i have in my delete event Handler..
private void dgStudents_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int rowToDelete = e.Item.ItemIndex;
dsStudents.student.Rows[rowToDelete].Delete();
//refresh datagrid control to show changes
BindData();
}
the rowToDelete int will get the row to delete, but when i run this and click on delete, i get a runtime error of "There is no Row at position 0"
Help please??
Cheers
|
|
|
|
|
I have a class "Foo" with a flag-type enum property that I do NOT want to serialize by name as many of the values can be serialized as a combination of misleading things (some of the flags have different meaning based on other flags, so both "LanguageSpanish" and "ChicagoBears" could have the same enum value of 5. With default serialization, if I meant to use LanguageSpanish, I could end up receiving ChicagoBears or vice-versa). Therefore, I am attempting to get this enum value as an integer. I do this by adding another property to my class that is of type ulong (the base type of the enumeration). However, the ulong type is serialized as a base-10 integer, when I want it to be in hex representation as it is a flags field. Is there any way to get the ulong property (or the enum) to serialize in hex, or am I resigned to using a string as the property type? The following example illustrates what I mean assuming the enum type I am using is "AnotherFlag | LanguageSpanish".
public enum TestEnum : ulong {
ChicagoBears = 5,
LanguageSpanish = 5,
AnotherFlag = 8,
...
}
[Serializable]
public class Foo {
public TestEnum EnumValue { get; set; }
public ulong UlongValue { get; set; }
public string StringValue { get; set; }
} Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Implement the System.Runtime.Serialization.ISerilizable interface and go nuts. Don't forget the protected constructor for deserializatoin.
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
I was hoping there was simply a setting on the serialization engine, but I guess this will do (using IXmlSerializable... ISerializable didn't work for me). I am slightly concerned, however, since a client needs my deserializer on the other side. I will have to try to mimick the auto-generated xml so a C# programmer can interface with my web service using only the WSDL. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
How come ISerializable does not work for you?
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
I don't know, but when I implemented that interface (and the corresponding constructor), nothing changed. The code within those methods was never executed. I am serializing these objects to/from a web service, which is apparently different from other methods of serialization. Almost everyone who has given me serialization advice tells me the same thing you told me, so I must be implementing the uncommon case or something. Anyway, thanks again for the help,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Ok, I understand. ISerializable is for binary serialization.
For XML, what you could do is implement properties and decorate them with the attributes of the System.Xml.Serialization namespace. For instance, suppose you want to serialize an enum into an hexadecimal string:
<code>
public class MyClass
{
public enum SomeEnum
{
EnumValue1 = 1,
EnumValue2 = 2
}
private SomeEnum _myEnum = SomeEnum.EnumValue1;
[XmlElement(ElementName="MyEnum")]
public string MyEnumAsHexString
{
get
{
return String.Format("{0:X}", (int)this._myEnum);
}
set
{
int enumValue = Int32.Parse(value, NumberStyles.AllowHexSpecifier);
this._myEnum = (SomeEnum)enumValue;
}
}
[XmlIgnore]
public SomeEnum MyEnum
{
get
{
return this._myEnum;
}
set
{
this._myEnum = value;
}
}
}
</code>
So, in the example above, your web service will serialize only the hexadecimal string property because the other one is tagged with [XmlIgnore].
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Yeah, I thought about doing that, but didn't like the fact that it no longer contained information about the type. Clients (of my WS) would see a string that looks like hex, but maybe it is a GUID without the slashes, or an IPv6 ip address without the colons... you get the idea. I was hoping there was an attribute to tell the serializer, "I have this enum that I want you to pass by hex value", then clients on the receiving end would get the type as enum and it would deserialize appropriately. Anyway, I came up with a different (probably better) way of doing what I was attempting to do (combining multiple fields into a single flags value). Instead of combining fields in a cryptic way for the end user of my service, I simply serialize a more verbose object back, splitting the fields into their own properties. The following illustrates this:
public enum Language {
Spanish = 1,
English = 2,
}
public enum Country {
USA = 1,
DEU = 2,
}
public class CountryAndLanguage { ... }
The reason I was attempting the first way was because I was misinformed that I could not return abstract types from a web service. Therefore, I thought that I had to have a concrete return type that would hold all the information contained within all derived types. This is incorrect, which is why I am now using the "correct" way of doing this mentioned above. Thanks again for the help,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
I don't know if this will work with SOAP, but you get the idea: A property that is used for serialization and another that is used in C# code.
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Hi all! How i can to invoke SQL Function through SqlCommand class,
what syntax i should use in CommandText and what value i should define in CommandType
THANK
|
|
|
|
|
Are you using an Article or tutorial? If not you should, there are many Database related articles here on Code Project. Use the Site Menu on the left side of the page to find them.
|
|
|
|
|
For scalar UDFs (which return a single value) use:
select dbo.MyUdfName()
For table-valued UDFs (that return a resultset) use:
select * from dbo.MyUdfName()
Regards
Andy
|
|
|
|
|
Hi all
I would like to trigger a function (writing a time stamp)
when Visual Studio is running in Debug Mode and an exception is thrown by the code.
I am basically interested in the event OnExceptionRaised in Visual Studio.
I saw that there is some DebuggerEventClass but it is something internal that cannot be used.
Is there any way to do that? I noticed that VIsualStudioIDE supportsa COM component model
but I think that this is not also supported.
Kind Regards
ManuStone
|
|
|
|
|
Hi,
I have an mdi parent form (frmMain) and a child form (frmChild)
Using c#, How is it possible to set the height of the child form as long as that in the frmMain i.e. the parent form.
At present the frmChild appears in the middle of frmMain but there is room for the frmChild's height to be increased.
Tried frmChild.height but .height does not appear in the intellisense.
Thanks
|
|
|
|
|
A form has a Size property.
ChildForm child = new childForm();
child.MdiParent = this;
child.Size = new Size(this.Width, this.Height);
child.Show();
This will set the height and width of the child form to be the same as its parent form.
|
|
|
|
|
I get a scrollbar on the parent form because the child form seems to be too long.
Any thoughts please?
This is what I have
Form frmNew = new frmChild();
frmNew.MdiParent = this;
frmNew.Size = new Size(frmNew.Width, this.Height);
frmNew.Show();
|
|
|
|
|
frmNew.Size = new Size(frmNew.Width, this.ClientSize.Height);
|
|
|
|
|
That still gives a scrollbar.
|
|
|
|
|
Wierd, I'm sure that's how I've done it before!
This way works if you want width and height:
In your child form's load event put...
this.Dock = DockStyle.Fill;
|
|
|
|
|
It depends how you will use your child form. I cant seem to get the child form to appear within the client rectangle without scroll bars apart from hacking it. So here is a couple of options you could have a look at.
1. You can set the child forms Dock = Fill.
2. You can set the child forms WindowState = FormWindowState.Maximized.
3. You can set the childs size to parentForm.ClientRectangle - x. (hack i know)
Sorry I am all out of ideas after that. The scroll bars seem to appear no matter if i set the hscroll etc props.
|
|
|
|
|
Solved it by doing this:
frmNew.Size = new Size(frmNew.Width, this.Height - 80);
Thanks
|
|
|
|
|
You may want to check the value of this.Height before you run this line of code. Setting the size to a negative number could be detrimental to the execution of your application.
|
|
|
|
|
Ok, I've checked the code that I used in a previous project and this works fine:
this.Height = this.Parent.ClientSize.Height;
Using this.MdiParent.ClientSize.Height doesn't however - strange!
|
|
|
|
|
Is there any code in C# to get GUID of network card.
Thanks.
The great pleasure in life is doing what people say you cannot do.
|
|
|
|