|
I declare a struct like this :
struct dataSeg
{
char[] QN;
char[] PNUM;
StringBuilder CP;
}
I want to init the member such as QN,PNUM,CP
How can I init the QN.......?
My meaning is:when I declare a variable of dataSeg ,I want QN, the member of the variable,can be alloc 20 bytes?
How can I get the result?
|
|
|
|
|
Use a class and do that:
char[] QN = new char[20];
Struct don't allow field initializers.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I would strongly advice you to make a class instead of a struct, as the data that you store in it are objects.
In the constructor you can create the objects. Example:
public dataSeg() {
this.QN = new char[20];
this.PNUM = new char[42];
this.CP = new StringBuilder();
}
I assume that you wanted the QN to be 20 characters, not 20 bytes, as 20 bytes would be 10 characters.
---
b { font-weight: normal; }
|
|
|
|
|
Hello,
I have a few comboboxes on the form. They all have the same datasource, the only thing I want to implement is if one of the comboboxes has a value selected, it will be filtered out from the other comboboxes, meaning you can't select the same value in two, or more comboboxes, it can only appear in one combobox. Is there a way to do it?
Thank you.
|
|
|
|
|
i didn't find any direct method for it but you can achieve desired behaviour by making copy of datasource and filter datasource when selected value of a combobox get change.
sameer
|
|
|
|
|
Some controls have properties that are ambient, which makes them set as the controls parent/container. Does anyone know how this can be avoided? I have found this to be connected to the Site-property in controls, but cannot see how I am to go about it if it's at all possible.
Any hints?
All needed for evil to prevale is for good men to do nothing.
C
|
|
|
|
|
if you want to display a control so you have to embedded it some where.so parent child relationship get genrated automatically.so you cant avoid it.to access added control you can use container.Controls
sameer
|
|
|
|
|
Hi all,
i have a peculiar problem in closing the windows forms.
In order to work with multiple instances of same form asynchronously,i am invoking the method using the beginInvoke method of a delegate as follows:
testDelegate del = new testDelegate(SubmitData);
del.BeginInvoke(null, new object[] { });
Its working fine . But when i close these instances, application is getting hanged.
In close button i just wrote this.close() method.
This application is a .net 2.0 windows application.
Can any one help me out to solve this please...
Thanks,
Pranu.
|
|
|
|
|
We'd need more code to help you out. SubmitData, what does that function look like? If your app hangs on close, can you pause execution under a debugger and see what it's trying to execute?
Another possibility: each thread, apart from the main UI thread, should have its Thread.IsBackground property set to true. Otherwise, your app will stay alive while those threads are running.
|
|
|
|
|
I have the following output from a webBrowser scrape and need to estract the XML section using C#;
</td>
</tr>
</table-->
<itemData><userID>-99999</userID>
<introducerID>-99999</introducerID>
<branchID>-99999</branchID>
<softwareID>-99999</softwareID>
<errorID>1</errorID>
<errorDesc>The branch Id supplied does not correspond with a branch in the system.</errorDesc>
</itemData>
<style>
table.cfdump_wddx,
table.cfdump_xml,
Im currently using string contentText = response.Substring(response.IndexOf("<itemData>")+0,218); as a means of getting the start but cannot get the end of the string and end up getting into the style tag.
Can anyone help??
|
|
|
|
|
Regular expressions work well for that:
Match match = Regex.Match(strHtml, @".*(?<XML>\<itemData\>.*?\</itemData\> ).*",
RegexOptions.Singleline | RegexOptions.IgnorePatternWhiteSpace);
string xmlFragment = match.Groups["XML"].Captures[0].Value;
|
|
|
|
|
Tried this but im getting an error on the IgnorePatternWhiteSpace;
C:\projects\projectGreen\WindowsApplication2\Form1.cs(67): 'System.Text.RegularExpressions.RegexOptions' does not contain a definition for 'IgnorePatternWhiteSpace'
Tried to solve to no avail
|
|
|
|
|
It is IgnorePatternWhitespace
Not IgnorePatternWhiteSpace
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it!
|
|
|
|
|
How to make the scanning step in the compiler ?
|
|
|
|
|
Could you clarify what you mean? Are you trying to induce the compiler to perform a code scan, or are you trying to compile C# code yourself?
|
|
|
|
|
Hi all,
I have added some items to a listview that has checkboxes, in the form's load method.
ListViewItem _selectionitem;<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM A");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM B");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM C");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM D");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM E");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM F");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM G");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM H");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM I");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM J");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM K");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM L");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM M");<br />
_selectionitem = listboxSelect_List.Items.Add("ITEM N");
I want to make all the checkboxes in the listview be checked but can't seem to get it right... i've been struggling for a while now.
If anyone knows how please let me know.
Thank you. (I'll keep trying and let you know if i get it right first)
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
foreach (ListViewItem lstItem in _selectionitem)
{
lstItem.Checked = true;
}
Hogan
|
|
|
|
|
Hey NarutoFan#1,
You can use the Checked property of the ListViewItem class, and set it to true after each item addition:
_selectioitem = listboxSelect_List.Items.Add("ITEM A");
_selectionitem.Checked = true; or:
listboxSelect_List.Items.Add("ITEM A").Checked = true;
Alternatively, you can use a foreach loop after adding all of the items:
.
.
.
_selectionitem = listboxSelect_List.Items.Add("ITEM N");
foreach (ListViewItem item in listboxSelect_List.Items)
item.Checked = true; Best Regards,
Shy.
PS
Naruto rocks! :P
|
|
|
|
|
Thank you. I appreciate the help.
Glad to see another Naruto fan...
I hope you enjoy "BLEACH" aswell... Great anime.
Enjoy the rest of your day.
Thanks once again.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
Good day
I am trying to write an application that will change a windows account details. If the account is running under the Local System Account, I can change it though my application so that it impersonate user particular user.
The problem now is that I'm battling to change a windows service so that it runs under Local System and not under an impersonated account - if it was already running under an impersonated account. Can anyone please help me with this.
Thanx in advance
Kulile --- RSA
|
|
|
|
|
Hello,
I have a Windows Application with .Net 1.1.
Problem is that I have to format (compl erase) the drive, like Windows Explorer does it.
Hope someone can help me, please.
Thanks in advance,
Martin
|
|
|
|
|
Hi all
I've re implemented the string object so the compareto method can detect numbers in a string and sort correctly.
sorted string values normaly appear like
test1
test10
test2
test20
test3
My mthod will sort like the following:
test1
test2
test3
test10
test20
test30
The only problem i have with it is that i cannot bind the object.
I've appended the code below:
using System;
namespace SortableString
{
using System;
using System.ComponentModel;
///
/// Summary description for SortableString.
///
#region SortableString
///
/// Serves as a container to String with the added ability to represent nulls.
///
[System.Diagnostics.DebuggerStepThrough()]
[Bindable(true)]
[Category("Data")]
[RefreshProperties(RefreshProperties.All)]
public struct SortableString : IComparable, IFormattable, IEditableObject
{
///
/// Represents a null String.
///
public static readonly SortableString Null;
// Memeber variables
private string m_Value;
private bool m_HasValue;
private bool inTxn;
private string backupData;
#region Constructors
///
/// Constructor to create a SortableString with an actual String value.
///
/// <param name="value" />
public SortableString(string value)
{
m_Value = value;
backupData = value;
m_HasValue = true;
inTxn = false;
}
///
/// Constructor to create a SortableString from another one.
///
/// <param name="obj" />
public SortableString(SortableString obj)
{
// Copy the internal members from the other object.
this.m_Value = obj.m_Value;
this.m_HasValue = obj.m_HasValue;
this.backupData = obj.backupData;
inTxn = false;
}
#endregion
#region Public properties
///
/// Exposes the actual String value.
/// This property will throw an exception when null.
///
public string Value
{
get
{
// Is there a value?
if (m_HasValue)
{
// Return the value
return m_Value;
}
else
{
// The object represents null, throw an exception.
throw new InvalidOperationException("Cannot provide a value when null.");
}
}
set
{
// Set the value
m_Value = value;
m_HasValue = true;
}
}
///
/// Indicates whether or not the value represents null.
///
public bool IsNull
{
// IsNull is the opposite of HasValue
get {return !m_HasValue;}
set {m_HasValue=!value;}
}
///
/// Readonly. Indicates whether the nullable type has a value (not null).
///
public bool HasValue {get {return m_HasValue;}}
///
/// Exposes the value for binding consumers.
/// The object in this property can be either null or an actual String value.
/// Trying to set the property to anything else would throw an exception.
///
public object BindableValue
{
get
{
// Return null for Nulls or the actual String value otherwise.
if (m_HasValue)
return m_Value;
else
return null;
}
set
{
// Consumer setting the value to null.
if (value==null || value==System.DBNull.Value)
SetToNull();
else
{
try
{
// Set the value
m_Value = (string)value;
m_HasValue = true;
}
catch (Exception ex) {throw new InvalidOperationException("SortableString: BindableValue only accept null or a String.", ex);}
}
}
}
///
/// Exposes the value for working with data objects.
/// The object in this property can be either DBNull.Value or an actual String value.
/// Trying to set the property to anything else would throw an exception.
///
public object DataValue
{
get
{
// Return null for Nulls or the actual String value otherwise.
if (m_HasValue)
return m_Value;
else
return DBNull.Value;
}
set
{
// Consumer setting the value to null.
if (value==DBNull.Value)
SetToNull();
else
{
try
{
// If not null, accept only valid String values.
m_Value = (string)value;
m_HasValue = true;
}
catch (Exception ex) {throw new InvalidOperationException("SortableString: DataValue only accept DBNull.Value or a String.", ex);}
}
}
}
///
/// Returns the value if one exists or a default value otherwise.
/// This property will always return a value and never throw an exception.
///
public string SafeValue
{
get
{
// Do we have a value?
if (this.m_HasValue)
return this.m_Value; // Return the real value
else
return string.Empty; // Return a default value
}
set
{
// Set the value
m_Value = value;
m_HasValue = true;
}
}
#endregion
#region Casting operations
///
/// Implicit cast from a string to a SortableString.
/// Note: The cast is implicit because we never lose information when converting a string to a SortableString.
///
/// <param name="value" />
/// <returns>
public static implicit operator SortableString(string value)
{
return new SortableString(value);
}
public static implicit operator string (SortableString value)
{
return value.Value;
//return new SortableString(value.SafeValue);
}
///
/// Explicit cast from SortableString to a string.
/// Note: The cast is explicit because it isn't always possible to convert a SortableString to a string.
/// When the SortableString represents null trying to cast it to a string will throw an exception.
///
/// <param name="value" />
/// <returns>
// public static explicit operator string(SortableString value)
// {
// if (value.m_HasValue)
// {
// // Otherwise, return the actual value.
// return value.m_Value;
// }
// else
// {
// return string.Empty;
// }
// }
#endregion
#region Methods
///
/// Sets the value to null.
///
public void SetToNull() {this.m_HasValue = false;}
public override int GetHashCode()
{
// Have we got a value?
if (this.m_HasValue)
{
// Otherwise use the value's hash code.
return this.m_Value.GetHashCode();
}
else
{
// This represents null so always return 0 (because the value is then irrelevant).
return 0;
}
}
///
/// Check two SortableString objects for eqaulity.
///
/// <param name="obj" />
/// <returns>
public override bool Equals(object obj)
{
// Is the provided object of the right type?
if (obj is SortableString)
{
// Are they equal (both null or both have the same value)?
return this.DataValue.Equals(((SortableString)obj).DataValue);
}
else
{
// The object is of the wrong type, cannot compare.
return false;
}
}
public override string ToString() { return ToString(null, null); }
public string ToString(String format, IFormatProvider fp)
{
//Ignore any formatting
return Value;
}
#endregion
#region IComparable implementation.
public static int Compare(SortableString obj1, SortableString obj2)
{
return obj1.CompareTo(obj2);
}
public int CompareTo(object obj)
{
//Check if Equal
if (obj.ToString() == Value) return 0;
//Format the strings so the numbers are padded with zeros
string s2 = ConvertToNumberedString(obj.ToString());
string s1 = ConvertToNumberedString(Value);
//Now check which ones greater.
return s1.CompareTo(s2);
}
///
/// Will Format a string with numbers so the numbers have leading zeros.
/// eg "this10" becomes "this00010"
/// eg "this1Is2Good" becomes "this00001Is00002Good"
///
/// <param name="s" />
/// <returns>
string ConvertToNumberedString(string s)
{
string op = string.Empty;
string sNum = string.Empty;
for (int i = 0; i < s.Length; i++)
{
//If Digit in Character then add the character to the number field.
if (char.IsDigit(s,i))
sNum = sNum + s[i].ToString();
else
{
//If we have numbers in the number field Format them.
if (sNum.Length > 0)
{
op = op + sNum.PadLeft(5,'0');
sNum = string.Empty; //Clear the number field incase of more than one group of digits.
}
op = op + s[i].ToString();
}
}
//Flush any remaining numbers at the end of the text
if (sNum.Length > 0)
op = op + sNum.PadLeft(5,'0');
//return the string back.
return op;
}
#endregion
#region IEditable Object Implementaion
// Implements IEditableObject
void IEditableObject.BeginEdit()
{
if (!inTxn)
{
this.backupData = m_Value;
inTxn = true;
}
}
void IEditableObject.CancelEdit()
{
if (inTxn)
{
this.m_Value = backupData;
inTxn = false;
}
}
void IEditableObject.EndEdit()
{
if (inTxn)
{
backupData = new SortableString();
inTxn = false;
}
}
#endregion
}//end class SortableString
#endregion // SortableString
}
using System;
namespace SortableString
{
///
/// Summary description for Class1.
///
public class C1
{
private string m_string1;
private string m_string2;
private SortableString m_sString;
public C1()
{
//Set the conttrols
m_sString = string.Empty;
m_string1 = string.Empty;
m_string2 = string.Empty;
}
public string String1
{
get { return m_string1; }
set { m_string1 = value; }
}
public string String2
{
get { return m_string2; }
set { m_string2 = value; }
}
public SortableString SS
{
get { return m_sString; }
set { m_sString = value; }
}
}
}
added a new form and create an new instance of c1 then bind value ss to a text box and try editing the value.
If anyone can tell me where i'm going wrong or can point me to a useful example or topic that would be great.
Thank you
|
|
|
|
|
hi
I need to create a .net dll which takes a VT_STREAM (which I think is in .net a IStream), do some magic and then return it.
My questions:
- Is there a aquivalent of VT_STREAM in .net 2.0?
- Is there something like a Stream which implements the interface IStream? (For casting)
- Is there a class which takes a IStream and converts it to text and text to IStream?
That's what I have now, but it doesn't work . It should only give you a better understanding of my problem.
namespace teststream
{
[ComVisible(true)]
[Guid("8e87823b-3354-405b-b192-8e8ba5b30c00")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ITestStream
{
[DispId(1)]
object testStream(IStream test);
}
[ComVisible(true)]
[Guid("397b9402-ac3b-4b73-bb8e-aa54bc55eef7")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("test.TestStream")]
public class TestStream : ITestStream
{
public TestStream()
{
}
public object letsTryToStream(ITestStream test)
{
/* Here should be somthing like test.ToString() */
doStuff();
doFoo();
return streamback;
}
}
}
thanks for your help!
greetings chris
|
|
|
|
|
hot to make a call to a webservice from the browser??
I have a simple webservice that adds two numbers.
http://localhost/hello/MyManagedClass.asmx
i want to pass parameters i,j to the webservice, form the browser addressbar, HTTP
can someone say how to pass parameters to the webservice from the addressbar??
thanks in anticipation...
Sincerely,
Baajhan
|
|
|
|
|
http://servername/vdir/webservicename.asmx/Methodname?parameter=value
Taken from: http://msdn2.microsoft.com/de-de/library/45fez2a8.aspx (German)
|
|
|
|