|
Thats because it's expecting T which is the type of element in the list. If your creating a list of strings then you should declare it as List<string><string> myList = new List<string><string>();</string></string>
|
|
|
|
|
|
Hello,
I am new to .net i develop a project in that am using C# coding. i used a MDI form in that i declar the Login form as achild to MDI. now i want to lock the MDI parent form, till i give the username and password.
In that application first the MDI parent form is invoked first then it call the login form.
Help plz .....
kethare
|
|
|
|
|
You should open the login form as a dialog rather than the child of the MDI, that way you prevent access to the controls on the MDI form.
|
|
|
|
|
Does anybody know how to create an efficient Undo/Redo Class? What are the general things I need to implement?
may your code be error free
|
|
|
|
|
There are several articles at cp so search
|
|
|
|
|
|
I need to add RADIUS server capability to a application suite I am developing. Does anybody know of a source for a library that will do this easily? Thanks.
|
|
|
|
|
A quick Google search revealed some interesting results, including this one[^].
|
|
|
|
|
I have a grid view that has a number of templated fields. The gridview is populated using a stored procedure. What I want to do is get the values in each cell in a row. But I am not getting any value from the cell. The simplified code is as shown below. Any idea why the code is not showing the value in the cell.
protected void dgPayment_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
string claimNo = dgPayment.Rows[e.NewEditIndex].Cells[3].Text;
}
catch(Exception ex)
{
ex.Message.ToString();
}
}
|
|
|
|
|
You can try the following:
Check for the Edit Control type.
Get the control
Get the value stored there.
like:
if (e.Control.GetType() == typeof(DataGridViewTextBoxEditingControl))
{
DataGridViewTextBoxEditingControl EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
string claimNo = EditingControl.Text;
}
Manoj
Never Gives up
|
|
|
|
|
Thanks for the response.
However I am trying to get the values of each column in a row of a gridview.
|
|
|
|
|
Thanks Manoj.
Your suggestion works great. You have been a great resource in solving my problem.
|
|
|
|
|
Hi,
I decided to move DAL layer classes to dll. Since that, my application communicate with database very slow (one time faster, another slow).
Trying to solve that problem I'm loading dll library when application starts
AppDomain.CurrentDomain.Load("dal");
but it isn't working properly.
Could somenoe give me some suggestions?
|
|
|
|
|
I can suggest you few points:
1) Have you indexed you tables? Indexing improves performance.
2) How many connection are you using? If you are using a new connection for each call then its a bottleneck for the performance. You should use single or limited number of connections to the data base.
3) You can check you functins for passing parameters "by reference" whenever you can do.
4) In case your database is not reciding on the same PC then you can optimize your queries so that less data travels to the Application server PC
Manoj
Never Gives up
|
|
|
|
|
App was working fine before moving DAL to another assembly so I think all "connection logic" is OK.
|
|
|
|
|
I'm creating a Download Manager in C# which is now nearing completion. Can someone please inform me of how I could integrate this with Internet Explorer (and possibly even Firefox) so it automatically downloads files rather than the default downloader.
Thanks in advance,
Barguast
|
|
|
|
|
|
Thanks to anybody who feels like helping the beginner.
I want to create a system wherein objects are accessing each other and I struggle to understand reference passing. For example, I wish I could write a function that specifically targets one instance of a class, but I only see how to write functions that take object references as arguments such that I have to call the function with the correct reference each time. I show the way I tried, right in the middle of my code below with all the ????. How do I aim functions at specific objects, given that I only get to write function definitions when defining a class, and the other class's objects don't even exist yet? And, in my code, do I correctly comment the things which do seem to work as intended?
Also, there seems to be nothing in the books about this. Doesn't this trip up everybody when they first try to access one object from another? There's stuff about the Observer pattern and deligates and ref modifiers and values versus references, but nothing directly about this basic point. Is there a name or keyword for this topic or for a discussion of this?
By the way, I understand having objects talk directly can tangle things and is a mixed blessing. I still want to grasp the idea.
I'm using:
Programming C# (Liberty)
The C# Programming Language (Hejlsberg...)
C# In a Nutshell (Drayton...)
C# Essentials (Albahari...)
Murach's C# (Murach)
Visual C# 2005 Demystified (Kent)
The Object-Oriented Thought Process (Weisfeld)
as well as several C++ books like Eckel and Prata and the MSDN and CodeProject forums.
Thanks!!
using System;
// Here is an exercise between objects, that studies reference passing.
// The Main function instantiates User, Counter and Reporter objects and
// calls on some of their members. Since the objects are in scope in Program,
// no passing of references is needed. However, when Main asks a Reporter's
// method to call members of User and Counter objects, Main must pass
// Reporter references to the User and Counter objects. But the Reporter
// needs no reference to reach method in static FunctionHolder class.
// ???? I wanted to define a method that specifically accesses Counter2
// ???? instance of Counter but don't see how to do so! See line 95.
namespace ClassesAndObjects
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Initialize all.");
// Construct 3 Users, 2 Counters and a Reporter
Reporter ConcreteReporter = new Reporter();
User User1 = new User();
User User2 = new User();
User User3 = new User();
Counter Counter1 = new Counter();
Counter Counter2 = new Counter();
// Try a bunch of things, reporting various properties each time
// This function call needs object references but no static class ref:
ConcreteReporter.Report(User1, User2, User3, Counter1, Counter2);
Console.WriteLine("Do User1.Make6()");
// User1.Make6() is in scope, no reference passing required
User1.Make6();
ConcreteReporter.Report(User1, User2, User3, Counter1, Counter2);
Console.WriteLine("Do User1.X = 9");
User1.X = 9;
ConcreteReporter.Report(User1, User2, User3, Counter1, Counter2);
Console.WriteLine("Do Counter1.Increment()");
Counter1.Increment();
ConcreteReporter.Report(User1, User2, User3, Counter1, Counter2);
Console.WriteLine("Do User1.X = Counter1.I");
User1.X = Counter1.I;
ConcreteReporter.Report(User1, User2, User3, Counter1, Counter2);
Console.WriteLine("Do Counter2.Increment() Twice");
Counter2.Increment();
Counter2.Increment();
ConcreteReporter.Report(User1, User2, User3, Counter1, Counter2);
Console.WriteLine("Do User2.XGetsI(Counter2)");
// Must pass reference, which tells User2 which Counter to call.
User2.XGetsI(Counter2);
ConcreteReporter.Report(User1, User2, User3, Counter1, Counter2);
Console.WriteLine("Do User2.X = Counter2.I");
User2.X = Counter2.I;
ConcreteReporter.Report(User1, User2, User3, Counter1, Counter2);
Console.WriteLine("Do Counter2.Increment()");
Counter2.Increment();
ConcreteReporter.Report(User1, User2, User3, Counter1, Counter2);
Console.WriteLine("Do User3.XGetsIFromCounter2(Counter1), it uses Counter1");
// Must pass reference, which (unfortunately) is what chooses the counter
User3.XGetsIFromCounter2(Counter1);
Console.WriteLine("Look, did not read Counter2 as intended:");
ConcreteReporter.Report(User1, User2, User3, Counter1, Counter2);
Console.WriteLine("Do User3.XGetsIFromCounter2(Counter2), it uses Counter2");
// This time, pass reference to the counter that was intended all along
User3.XGetsIFromCounter2(Counter2);
Console.WriteLine("Look, it read Counter2, just because of the reference:");
ConcreteReporter.Report(User1, User2, User3, Counter1, Counter2);
// Keep console window open for examination.
Console.ReadLine();
}
}
public class User
// Objects of this class can directly use a property in objects of Counter class
// and have members the Reporter and Program objects can directly call
{
private int x;
public User()
{
x = 5;
}
public void Make6()
{
x = 6;
}
// NOTE this function needs a reference to the Counter object
public void XGetsI(Counter CounterN)
{
// Expression uses the reference I passed in as argument
X = CounterN.I;
}
// ????????????????????????????????????????????????????????????
// How could I define a function that specifically targets Counter2?
// Lines below just use "Counter2" as a local identifier
// the same way "CounterN" is used a few lines above so this code
// does NOT specify Counter2, which wouldn't exist here anyway.
// ???????????????????????????????????????????????????????????
public void XGetsIFromCounter2(Counter Counter2)
{
X = Counter2.I; // Unfortunately this doesn't mean my Counter2 object!
}
public int X
{
set
{
x = value;
}
get
{
return x;
}
} // end property X
} // end class User
public class Counter
// Objects of this class have a property and a function which
// User, Reporter and Program objects will directly call
{
private int i;
public Counter()
{
i = 0;
}
public int I
{
get
{
return i;
}
}
public void Increment()
{
i = i + 1;
}
} // end class Counter
public class Reporter
// Function in an object of this class will directly call members of User and Counter objects
// and of the static class FunctionHolder. This function requires User and Counter object
// references as arguments because those objects are only instantiated in another class at
// runtime and do not yet exist during the definition of this class. But it does not need
// to be passed a reference to the static class FunctionHolder because that doesn't wait
// for a runtime instantiation.
{
public Reporter()
{
// No data members to initialize
// Could put singleton construction in here
}
public void Report(User User1, User User2, User User3, Counter Counter1, Counter Counter2)
{
Console.WriteLine("U1.X={0}, U2.X={1}, U3.X={2}, C1.I={3}, C2.I={4}, Fifty={5}\n", User1.X, User2.X, User3.X, Counter1.I, Counter2.I, FunctionHolder.Fifty());
} // end class Reporter
}
public static class FunctionHolder
// This class is static and others use its method with just ClassName.MethodName().
{
public static int Fifty()
{
return 50;
}
} // end class FunctionHolder
} // end namespace ClassesAndObjects
|
|
|
|
|
You're doing good, it's apparent you're picking up some things pretty well.
I see your problem. You're thinking, "how can I write a function that just works on some particular object instance (e.g. Counter2)"?
The problem is, that's not the way functions work supposed to work. Functions in C# are either instance functions (they work on the current instance) or static (they work on any instance you pass them). For example, say you want a SayHello() method on your Counter object. You can code it up to work on all Foo objects:
class Counter
{
public string MyName;
public void SayHello()
{
Console.WriteLine(MyName);
}
}
Now you can go like this:
Counter counter1 = new Counter();
counter1.MyName = "I am the first counter!";
Counter counter2 = new Counter();
counter2.MyName = "I am the second counter!";
counter1.SayHello();
counter2.SayHello();
See what happened? The SayHello method worked on the current instance.
Static methods don't belong to any instance; therefore they have to be passed the instance to work on:
class Counter
{
public static void StaticSayHelloMethod(Counter instanceToUse)
{
Console.WriteLine(instanceToUse.MyName);
}
}
Now if you want to use that, you have to pass the instance in:
StaticSayHelloMethod(counter1);
StaticSayHelloMethod(counter2);
Does that answer your question?
p.s. next time use <pre> tags around your code (e.g. <pre> code goes here </pre> ) when you post it on the forums. This way, formatting will be preserved, your code will be easier to read on the forums, and the likelihood of someone answering your question increases.
|
|
|
|
|
Judah, yes, thanks, that's it perfectly. I guess this means there'd be a frequent pattern where a sort of a "switchboard" or "coordinator" object manages the calls of other objects on each other? Maybe there's also a way for objects of the same class that are in an array or collection together to know how to call, say, their North or West neighbor, like if you're iterating on a finite element mesh or convolving pixel values throughout an image (or maybe the "coordinator" object just foreach's through the array calling methods with (i,j) and (i+1,j) indices).
And thanks for the
tip, I'll use it!
|
|
|
|
|
I need to run an executable program from a C# program and I need to run the program of a a number of times and I have to save the output each time. I tried something but it saves my only the last output. How can I do it?
|
|
|
|
|
You can use System.Diagnostics.Process class to run external programs. You can use Process.StandardOutput to get the output of each process.
|
|
|
|
|
If you use the process class you can execute your application. If you tie into the standard output you can receive that output and do stuff with it. I have an example of this in this article I wrote:
http://www.codeproject.com/dotnet/OpenFiles.asp[^]
Hope that helps.
Ben
|
|
|
|
|
sounds like a bug in your code. Care to show code ?
|
|
|
|
|