Hi, Have you ensured that you call DataBind() on your data grid after you set the data source? DataGrid dgMyDataGrid = new DataGrid(); DataSet dsMyData = new DataSet(); ... Setup your dataset ... dgMyDataGrid.DataSource = dsMyData.Tables[0]; **dgMyDataGrid.DataBind();**
Give that a shot! Nick. Nick.
Nick Pirocanac
Posts
-
DataGrid In ASP.NET Page? -
Maze program using recursive function UPDATED!Hello, One problem I see right away is that when you pass maze to your recursive funcion, you are passing it as a pointer to the array, not a copy of the array. When you set a point in the maze matrix to 'x', you are setting it globally, so that the maze matrix is permantly altered. This means, that the more times you are calling your recursion function, you are setting more and more of your maze to all 'x', and removing the path of '.'. When dealing with arrays in C/C++, you will always pass them as pointers to the underlying data, as opposed to passing a copy. If you want to stick with the method you are using above, you would have to make a new copy of the maze matrix before calling solve_maze each time. Check out the docs for memcpy()! maze[12][12]; newMaze[12][12]; memcpy(newMaze, maze, sizeof(newMaze)); // Do your switch to make the move, and apply the changes to the newMaze copy solve_maze(newMaze, ...); Note: Solving a huge maze with this method will eat a lot of memory, as you will make a new copy on each recusion level, leading to lots of copys when you get down deep in your tree. Good luck! Nick.
-
Dynamic list of classesTake another look at ValidRunnableClass. It's an abstract class which exposes one method, Run(). If you change your example above a hair, to look like: public class MyTestFuction : ValidRunnableClass { // Change the Execute call to match the Run() method in ValidRunnableClass. public override void Run(string [] args) { // do something here } } Now, you have a class that has a common interface. You can add more classes at will, without having to add any switch/cases at all. Next, to cause the execution check my example again: Type [] aTypes = System.Reflection.Assembly.GetExecutingAssembly().GetTypes(); foreach(Type oCurrType in aTypes) { if(oCurrType.ToString() == args[0] && oCurrType.IsSubclassOf(Type.GetType("RunArbitraryClasss.ValidRunnableClass"))) { // Get the constructor for the class to invoke the run method on. ConstructorInfo ci = oCurrType.GetConstructor(Type.EmptyTypes); // Create an instance of the class that is derived from // ValidRunnableClass. This will give us our prototype for invoking the // Run method on the subclass. ValidRunnableClass vrc = (ValidRunnableClass) ci.Invoke(null); // Drop the first arg from the args list. string [] passArgs = new string [args.Length - 1]; int i = 0; for(i = 1; i < args.Length; i++) { passArgs[i - 1] = args[i]; } // Execute the target class. return(vrc.Run(passArgs)); } } throw new Exception("A class was specified that is not subclassed from ValidRunnableClass!");} First, you create an instance of the ValidRunnableClass interface from a System.Type object. You do this with the System.Type.GetConstructor() function. Then, you use the ConstructorInfo.Invoke() method to create a ValidRunnableClass object. Then, you call the Run() method on the ValidRunnableClass which does your work. Because you extended MyTestFunction from ValidRunnableClass, it will call the proper method in MyTestFunction automatically! Ok, I think you should be able to make it go from here. Good luck! Nick.
-
Casting ProblemHi John, I don't think that you can cast classes, even if they derive from the same base class in C# (even tho this is legal in C++). Instead, something like this may get you where you want to go. Good luck! Nick. ----------------------------------------------------------- A Sample Run: D:\>ClassCasting.exe ClassA! ClassB! D:\> ----------------------------------------------------------- using System; namespace ClassCasting { /// /// Summary description for Class1. /// class ClassCasting { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { ClassA oClassA = new ClassA(); ClassB oClassB = new ClassB(); // Can't do this in C# yet! //oClassB = (ClassB) oClassA; // But.... you can do this! CoreClass oCoreClass = oClassA; oCoreClass.SomeMethod(); oCoreClass = oClassB; oCoreClass.SomeMethod(); } } abstract class CoreClass { // Define some common methods here. public abstract void SomeMethod(); } class ClassA : CoreClass { public override void SomeMethod() { Console.WriteLine("ClassA!"); } } class ClassB : CoreClass { public override void SomeMethod() { Console.WriteLine("ClassB!"); } } }
-
Dynamic list of classesHi! You can try this code snippit, I think it's what you want to do. I made this type of thing before for a Java proggie, and it was even easier in C#! Good Luck! A few runs look like: ------------------------------ RunArbitraryClasss.exe RunArbitraryClasss.NonRunnableClass arg1 arg2 Unhandled Exception: System.Exception: A class was specified that is not subclassed from ValidRunnableClass! at RunArbitraryClasss.RunArbitraryClasss.Run(String[] args) in c:\source\automation\runarbitraryclasss\runarbitraryclasss.cs:line 53 at RunArbitraryClasss.RunArbitraryClasss.Main(String[] args) in c:\source\automation\runarbitraryclasss\runarbitraryclasss.cs:line 20 ------------------------------ RunArbitraryClasss.exe RunArbitraryClasss.RunnableClass arg1 arg2 I'm a runnable class: arg1 arg2 Here's the source! --------------------------------------------------------------
using System; using System.Reflection; namespace RunArbitraryClasss { /// /// Summary description for Class1. /// class RunArbitraryClasss { /// /// The main entry point for the application. /// [STAThread] static int Main(string[] args) { // Get the program running. RunArbitraryClasss oRunArbitraryClasss = new RunArbitraryClasss(); return(oRunArbitraryClasss.Run(args)); } public int Run(string[] args) { // Get a list of valid types. Type [] aTypes = System.Reflection.Assembly.GetExecutingAssembly().GetTypes(); foreach(Type oCurrType in aTypes) { if(oCurrType.ToString() == args[0] && oCurrType.IsSubclassOf(Type.GetType("RunArbitraryClasss.ValidRunnableClass"))) { // Get the constructor for the class to invoke the run method on. ConstructorInfo ci = oCurrType.GetConstructor(Type.EmptyTypes); // Create an instance of the class that is derived from // ValidRunnableClass. This will give us our prototype for invoking the // Run method on the subclass. ValidRunnableClass vrc = (ValidRunnableClass) ci.Invoke(null); // Drop the first arg from the args list. string [] passArgs = new string [args.Length - 1]; int i = 0; for(i = 1; i < args.Length; i++) { passArgs[i - 1] = args[i]; } // Execute the target class. return(vrc.Run(passArgs)); } } throw new Exception("A class was specified that is not subclassed from ValidRunnableClass!"); } } abstract class ValidRunnable
-
Date, time and Week numberI may not be thinking this through, but how about: int nWeek = Convert.ToInt32(DateTime.Now.DayOfYear / 7.0); Nick.
-
Calling self standing cpp files from a main cppHi DP, Not sure if your asking for this, but how about using defines to cause the compiler to not compile the main() functions inside your library modules? In the future, you might want to break up your modules further to not include main inside each part, but make seperate test harnesses for each library. Hope that's kinda what you are after. In the below example, use a preprocessor define for your Radix standalone to compile with a local main(). Don't define the STANDALONE_MODULE_RADIX for your composite program that uses several of your sort libraries, and you won't have the problem of multiple included main(). Good luck! Nick. //Radix.cpp: #ifdef STANDALONE_MODULE_RADIX //Main int main() { //Setup your sort data here, but don't sort it. // ... // Now, all your data is set in structures, call your sort! MyRadixSort(); // Done, do some outputting. //... } #endif // Your actual sort code goes here... void MyRadixSort() { } ---------------------------------- Your header file for Radix.cpp: // Radix.h void MyRadixSort(); ---------------------------------- Ok, here is the your main file that you would use with a bunch of your libraries: // real_main.cpp: #include Radix.h void main() { // Set up your data for this composite program // Call your sorts... // ... MyRadixSort(); // All done! }
-
How to set the value of a system environment variable from the command line?Check out: http://www.winnetmag.com/Articles/Index.cfm?ArticleID=5379 Here is the relevent blurb: If you want to use a batch file to assign values to variables, use the Setx resource kit utility. Setx is a powerful tool with which you can manage the environment variables in NT. This utility has three modes of operation: command line, Registry, and file. The command-line and Registry modes are the most common. You can find that utility in the NT Resource Kit. Good luck! Nick. Nick.