|
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)
|
|
|
|
|
HI chris,
i found the answer, thanks, it was useful.
well, i have been looking for some sample, that just does this: (a COM Wrapper)
1. A VB.NET COM Class that connects to the remote webservice,
2. Fetches the data from the WS, by passing a parameter to it,
3. Populate the values into the property of the COM Class
By doing so, I can consume the webservice form within a ASP or Vb6(un managed code) application.
Any ideas would be greatly appreciated. Thanks.
Baajhan
Sincerely,
Baajhan
|
|
|
|
|
I think it would be simpler to just create a proxy class and then compiling it as a .com object. I haven't tried it, but should also work.
Wsdl /language:vb /protocol:HttpPost /namespace:myNameSpace /out:yourfile.vb /username:username /password:password /domain:domain <url or="" path="">
look here: http://msdn2.microsoft.com/en-us/library/7h3ystb6.aspx
greetings chris
|
|
|
|
|
Hi guys,
I'm having a problem writing out a selialized dataset to a file.
I have a very big query that takes over an hour to run before it populates a dataset with data. I then process the data within the dataset.
It's not very time efficiend trying to debug the processing part of the code with this long delay so I'd like to dump the data to a binary file which I can load instead of running the query.
This is the code I'm using to try and save the dataset but I get an out of memory exception when I close the file stream.
Any help would REALLY be apreciated.
<br />
private void SaveDataToFile( string filePath )<br />
{<br />
try<br />
{<br />
this.m_dsModel.AcceptChanges();<br />
<br />
if( File.Exists(filePath) == true )<br />
{<br />
File.Delete( filePath );<br />
}<br />
<br />
FileStream fs = new FileStream( filePath, FileMode.Create, FileAccess.Write);<br />
<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
try <br />
{<br />
formatter.Serialize( fs, this.m_dsModel );<br />
}<br />
catch (SerializationException e) <br />
{<br />
System.Diagnostics.Trace.WriteLine( e );<br />
}<br />
finally <br />
{<br />
fs.Flush();<br />
fs.Close();<br />
}<br />
}<br />
catch(Exception ex)<br />
{<br />
System.Diagnostics.Trace.WriteLine( e );<br />
}<br />
}<br />
<br />
|
|
|
|
|
You can get and set XML strings from a dataset.
Something like:
DataSet ds;
string xml = ds.GetXml();<br />
<br />
<br />
ds.ReadXml(xml);
hope this helps.
|
|
|
|
|
how to pick n distinct (no repetition) strings randomly from an array of strings without using a while loop.
Any help appreciated.
Jad J.
|
|
|
|
|
wli ma7dood walla ma fhemna shi 3alayk.
n2ebir kttob meshkeltak metl el khale2 khalena nse3dak.
hehehehhe
yalla bye
jamil abou khalil
|
|
|
|
|
You might want to try your own homework first, and ask specific questions if you get stuck.
|
|
|
|
|
this[^] might help you. Search on Random
|
|
|
|
|
Hi,
I placed Gridview in my form and created boundfileds and template field. I placed Imagebuttons, hyperlinks in templatefield. I set the DataKeyNames property. After the grid is populated with some data, i want to show some tooltips when cursor is placed on the respective imagebutton and want to perform some task(like moving to next page based on the selectedrow datakeyname).
I was able to show the tooltip on mousehover. The code i worte is
protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)<br />
{<br />
if (e.Row.RowType == DataControlRowType.DataRow)<br />
{ <br />
ImageButton c1 = (ImageButton)e.Row.Cells[0].FindControl ("ctnBtn");<br />
if(c1 != null) <br />
{<br />
c1.Attributes.Add("onmouseover", "");<br />
c1.Attributes.Add("onmouseout", "");<br />
}<br />
}<br />
}
But not able to get the datakeyname of that particlar selected row.
protected void Gridview1_RowCommand(object sender, GridViewCommandEventArgs e)<br />
{<br />
if (e.CommandName == "ctn")<br />
{<br />
string key = Gridview1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString();<br />
string url = "qwer.aspx?key="+key.ToString(); <br />
Response.Redirect(url);<br />
....<br />
}<br />
}
I was able to get the e.commandname correctly and gettig into the loop but was not getting the
e.CommandArgument of the selected row. It is showing the null everytime.
I was able to implement this rowcommand function correctly when the imagebutton control is not in the template field.
Let me know how to implement the Findcontrol method for <asp:buttonfield> of GridView
Let me know where i went wrong in implementing the code.
Thanks in Advance.
|
|
|
|
|
I want to create an xml and put it to a string. I noticed that XmlWriter always adds an xml header and an encoding="..." attribute to this header. This encoding attribute becomes erroneous if I save the string as a file with some other encoding. Is there a better way to skip this encoding attribute than the one below?
StringBuilder builder = new StringBuilder();
XmlWriter writer = XmlWriter.Create(builder);
writer.WriteStartDocument();
writer.Flush();
builder.Replace(" encoding=\"utf-16\"", "");
writer.WriteStartElement("foo");
writer.WriteStartElement("bar");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
return builder.ToString();
The result of this is:
<?xml version="1.0"?><foo><bar /></foo>
|
|
|
|
|
I found another, similar way, using XmlWriterSettings.OmitXmlDeclaration:
StringBuilder builder = new StringBuilder();
builder.Append("<?xml version=\"1.0\"?>");
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
using (XmlWriter writer = XmlWriter.Create(builder, settings))
{
writer.WriteStartElement("foo");
writer.WriteStartElement("bar");
writer.WriteEndElement();
writer.WriteEndElement();
}
return builder.ToString();
|
|
|
|
|
hai all,
in c# is there any way to count the number of occurence of a specific character in a string?
my string is a,b,c,d,e,f
i need to count the number of commas in this string
All I ever wanted is what others have....
CrazySanker
|
|
|
|
|
hi,
u can use this code:
<br />
String str = "a,b,c,d,e,f";<br />
String []count = str.Split(',');<br />
int numOfOccurance = count.Length - 1;<br />
hope it helps
Jamil abou khalil
|
|
|
|
|
string x = "a,b,c,d,e,f";
int y = x.Split(',').Length - 1;
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|