|
if anyone can help me out please do all the information is found at this address
http://groups-beta.google.com/group/microsoft.public.dotnet.csharp.general/browse_thread/thread/b6e5879b1a6b8de0/31753bb8be88ade7#31753bb8be88ade7
Alexandre Brisebois
Alexandre.Brisebois@gmail.com
|
|
|
|
|
"this line produces the error :
temp = o.GetType().InvokeMember("", BindingFlags.CreateInstance, null,
null, null); "
1. Seperate the code, iow 1 instruction per line.
2. You trying to get the constructor? Use Type.GetConstructor.
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
|
|
|
|
|
hi experts
i have a string let say
string dummy="hello"
i want to remove 'h' and 'e' from this string and want to show a remaining string "llo" on the messagebox.
waiting for reply
|
|
|
|
|
string dummy = "Hello";
dummy = dummy.Replace("H", "");
dummy = dummy.Replace("e", "");
MessageBox.Show(dummy);
Forever Developing
|
|
|
|
|
Or, use the Substring() function. Depends on what exactly you want to do.
|
|
|
|
|
Using Com interop, I open an Excel worksheet. With Range's Find - method I search for a certain cell.
So far so good. Now the user should be able to edit this cell. But how can I make Excel scroll to that cell ?
|
|
|
|
|
Application.Goto (ActiveWorkbook.Sheets("Sheet2").Range("E6"))
Forever Developing
|
|
|
|
|
it works!!! Thanks very much
|
|
|
|
|
string test = "1";
test.Replace("1","2");
i tried doing this in something more complex like cleaning out characters in a big string, but even after this code i'm seeing .net ignore me...test should equal "2" after this, and it doesn't.
|
|
|
|
|
Strings are immutable in .NET. This is for thread safety and other reasons. Do this instead
test = test.Replace("1", "2");
-
Drew
|
|
|
|
|
Wow little ackward but owell...Thx for clearing that up for me
|
|
|
|
|
How can I get a dataset of selected rows in a DataGrid? It should get me the correct selected rows even if the grid is sorted on any one of the columns.
|
|
|
|
|
snnn wrote:
How can I get a dataset of selected rows in a DataGrid? It should get me the correct selected rows even if the grid is sorted on any one of the columns.
I am still looking forward for an answer. Would anyonr please help?
|
|
|
|
|
Hi,
We have this SelectedIndexChanged event that is raised by the .NET listview control.
I wonder why there is no SelectedIndexChanging event in the listview control. I have a need whereby i need to store the current index somewhere before the selectedindexchanged event is about to be raised. I can't see how i can achieve this. I certainly need an even that will tell me that the index is about to be changed. SelectedIndexChanged event is too late for me to store the index of the previously selected index.
Any ideas?
|
|
|
|
|
It might seem logical that you could derive from the control and dispatch a pre notification event, but that might not work because the control just wraps the Win32 API. So your best bet is to keep a previousSelectedIndex around. When your SelectedIndexChanged delegate is invoked you can do what you need to do, then store the previousSelectedIndex at that time. The next time your delegate is invoked the previousSelectedIndex will be the previous index.
-
Drew
|
|
|
|
|
Hey guys... first I just want to praise The Code Project and everyone on here for basically teaching me the basics of C#. I have a web background and this is the first language I have learned coming off my javascript and vbscript web knowledge.
I am sure this question has a very simple answer, but that is an answer I cannot figure out!
Here it is...
I have dummied down my problem into the following code examples. I have a very basic program that takes one richtext field and copies the content into another. I am doing so by calling a method in a separate class that accomplishes the copying of text.
Form1.cs:
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace TestApp<br />
{<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
private System.Windows.Forms.Label label1;<br />
public System.Windows.Forms.RichTextBox txtFromSecondClass;<br />
public System.Windows.Forms.RichTextBox txtToSecondClass;<br />
private System.Windows.Forms.Label label2;<br />
private System.Windows.Forms.Button button1;<br />
private System.ComponentModel.Container components = null;<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
#region Windows Form Designer generated code<br />
private void InitializeComponent()<br />
{<br />
this.txtFromSecondClass = new System.Windows.Forms.RichTextBox();<br />
this.label1 = new System.Windows.Forms.Label();<br />
this.txtToSecondClass = new System.Windows.Forms.RichTextBox();<br />
this.label2 = new System.Windows.Forms.Label();<br />
this.button1 = new System.Windows.Forms.Button();<br />
this.SuspendLayout();<br />
this.txtFromSecondClass.Location = new System.Drawing.Point(8, 200);<br />
this.txtFromSecondClass.Name = "txtFromSecondClass";<br />
this.txtFromSecondClass.Size = new System.Drawing.Size(280, 64);<br />
this.txtFromSecondClass.TabIndex = 0;<br />
this.txtFromSecondClass.Text = "";<br />
this.label1.Location = new System.Drawing.Point(8, 176);<br />
this.label1.Name = "label1";<br />
this.label1.Size = new System.Drawing.Size(272, 16);<br />
this.label1.TabIndex = 1;<br />
this.label1.Text = "From SecondClass:";<br />
this.txtToSecondClass.Location = new System.Drawing.Point(8, 32);<br />
this.txtToSecondClass.Name = "txtToSecondClass";<br />
this.txtToSecondClass.Size = new System.Drawing.Size(280, 64);<br />
this.txtToSecondClass.TabIndex = 2;<br />
this.txtToSecondClass.Text = "";<br />
this.label2.Location = new System.Drawing.Point(8, 8);<br />
this.label2.Name = "label2";<br />
this.label2.Size = new System.Drawing.Size(272, 16);<br />
this.label2.TabIndex = 3;<br />
this.label2.Text = "Send To SecondClass:";<br />
this.label2.Click += new System.EventHandler(this.label2_Click);<br />
this.button1.Location = new System.Drawing.Point(24, 120);<br />
this.button1.Name = "button1";<br />
this.button1.Size = new System.Drawing.Size(240, 32);<br />
this.button1.TabIndex = 4;<br />
this.button1.Text = "Send To Second Class";<br />
this.button1.Click += new System.EventHandler(this.button1_Click);<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(292, 273);<br />
this.Controls.Add(this.button1);<br />
this.Controls.Add(this.label2);<br />
this.Controls.Add(this.txtToSecondClass);<br />
this.Controls.Add(this.label1);<br />
this.Controls.Add(this.txtFromSecondClass);<br />
this.Name = "Form1";<br />
this.Text = "Form1";<br />
this.ResumeLayout(false);<br />
<br />
}<br />
#endregion<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new Form1());<br />
}<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
SecondClass.transferText(txtToSecondClass.Text);<br />
}<br />
<br />
private void label2_Click(object sender, System.EventArgs e)<br />
{<br />
<br />
}<br />
}<br />
}<br />
SecondClass.cs:
<br />
using System;<br />
<br />
namespace TestApp<br />
{<br />
public class SecondClass<br />
{<br />
public static void transferText(string x)<br />
{<br />
Form1 formObj = new Form1();<br />
formObj.txtFromSecondClass.Text = x;<br />
}<br />
}<br />
}<br />
Any input would be awesome. Thanks again for such a great site =)
P.S. This isn't an example of the real code I am working on, but does illustrate the problem I have. I know the above project can be very simply accomplished in one class.
|
|
|
|
|
your problem is that you are creating a new instance of form1.
You need to pass in the existing instance of form1
transfertext to take the existing instance
public static string transfertext(System.Windows.Forms.Form x)
{
return x.txtFromSecondClass.Text;
}
usage
string value = SecondClass.transfertext(this);
best of luck
Forever Developing
|
|
|
|
|
Hey thanks for the reply!
... and here is the but hehehe ...
Can you treat me like a moron, and show me the rewritten methods for each class? I just can't wrap my mind around this...
|
|
|
|
|
..\..\..\SecondClass.cs(12): 'System.Windows.Forms.Form' does not contain a definition for 'textFromSecondClass'
That is what I get when I try to use your code. I guess I have some reading to do.
Thanks anyway.
|
|
|
|
|
Hi there,
I'm kind of new to C# (that might explain this question).
I stuck with my code when I have to:
1. implement a list of pairs (string, int)
2. sort it by int
Could you give me some hints on points 1 & 2?
Thanks
Domo_
|
|
|
|
|
The first step is to define a structure to hold your data. I used the property accessors in this case because it is part of my habit. These aren't required but are there for good measure.
The second step is to define a class that will determine how you will sort your data. This class derives from the IComparer interface and implements the Compare method. For more robust code you could check the instance type of the objects to be sure they are of the Pair type.
The third step is to sort your array of data. This can be done by using the static Sort utility method on the Array class. This method will accept any standard Array and sort it using your comparer.
using System;
using System.Collections;
namespace ConsoleApplication1
{
class Pair
{
public String MyString
{
get
{
return _string;
}
set
{
_string = value;
}
}
public int MyInt
{
get
{
return _int;
}
set
{
_int = value;
}
}
private int _int;
private String _string;
}
class PairComparer : IComparer
{
#region IComparer Members
public int Compare(object x, object y)
{
Pair left = (Pair)x;
Pair right = (Pair)y;
return left.MyInt.CompareTo(right.MyInt);
}
#endregion
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
Pair[] pairs = new Pair[3];
pairs[0] = new Pair();
pairs[0].MyInt = 10;
pairs[0].MyString = "Ten";
pairs[1] = new Pair();
pairs[1].MyInt = 3;
pairs[0].MyString = "Three";
pairs[2] = new Pair();
pairs[2].MyInt = 1;
pairs[2].MyString = "One";
Array.Sort(pairs, new PairComparer());
foreach (Pair pair in pairs)
{
Console.WriteLine(
"Pair: {0} {1}" ,
pair.MyInt,
pair.MyString);
}
}
}
}
-
Drew
|
|
|
|
|
//Wrap this in a command button click event
System.Collections.ArrayList arylist = new ArrayList();
for (int i = 10; i >= 0; i--)
{
pairs values;
values.stringvalue = i.ToString();
values.intvalue = i;
arylist.Add(values);
}
IComparer comp = new MyCompare();
arylist.Sort(comp);
for(int i = 0; i<=10; i++)
{
pairs values = (pairs)arylist[i];
MessageBox.Show(values.intvalue.ToString() + " " + values.stringvalue);
}
//end wrap
private class MyCompare: System.Collections.IComparer
{
public int Compare(object x, object y)
{
pairs valuex = (pairs)x;
pairs valuey = (pairs)y;
if (valuex.intvalue < valuey.intvalue)
return -1;
if (valuex.intvalue > valuey.intvalue)
return 1;
return 0;
}
}
private struct pairs
{
public string stringvalue;
public int intvalue;
}
Forever Developing
|
|
|
|
|
|
Has anyone used embedded user controls (http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=187&printer=t) in a real application. I didn't even know this was possible until today.
I am building an app where the client wants drag-and-drop upload of multiple files. There is a Java tool out there, but I was considering creating an embeded user control.
Any suggestions? (No need to mention basic platform compatability issues).
|
|
|
|
|
I would see no real issues except that you will need to install .NET Framwork on the all of the machines that need this functionality.
Best of Luck
Forever Developing
|
|
|
|