|
Hi,
I have a DataGridView in my application which is bound to a BindingList... The control works perfectly when I use it in XP... But when I deploy the same application in Vista, some of the columns of the DataGridView interchange with each other and not in the order that I would want it to display... Can anyone tell me what could be done to have the DataGridView show columns in just the order it was while I designed? I've tried to explicitly specify the column's display index for each of the columns, but no luck..
Please note that this problem occurs only in Vista... It works fine in XP...
Thanks,
ramzg
|
|
|
|
|
Did you try to set compability to XP?
Are you using SQL commands?
Are the columns created programaticly or in design?
|
|
|
|
|
Hi Saksida...
Thanks for the reply..
Here are my replies to your queries...
Did you try to set compability to XP?
My application is compatible with XP... The problem occurs only when i run it on Vista.. And I dint set the compatibility explicitly...
Are you using SQL commands?
No, I'm not using any SQL commands.
Are the columns created programaticly or in design?
The columns were created at design time and values are added to them at runtime..
Thanks,
ramzg
|
|
|
|
|
I am currently reading on MSDN, try AutoGenerateColumns set to false
EDIT: Oh yeah that was your post on MSDN
|
|
|
|
|
Yup,
It was indeed my post... I'm yet to try it on vista... Will get back to you after I try it out...
|
|
|
|
|
I have compiled a C# dictionary that reads data from a text file. How can we embed or encrypt or hide wordlist text data file from end user. Can someone help with a small example. Thanks
|
|
|
|
|
Compile it as a resource within an assembly?
|
|
|
|
|
|
Yes. A good memory. Also need a working example as demo with my thanks in advance to sender.
modified on Wednesday, August 19, 2009 11:23 AM
|
|
|
|
|
I don't think people will send you a demo or code, but you can try Googling encrypting and C. You will be surprised at how easy it will be to get code from Google that nearly suits your entire model, with a need for only slight modification.
|
|
|
|
|
Thanks Eliott for advice on encryption . If feasible, prefer embedding txt file where application path is a difficulty. Its a freeware for my native community but I like to protect my translation work from duplication. I can send said work for a solution...
|
|
|
|
|
Hello.
I'm having a little problem with the Random() class generating the same number. Only the first index is being validated and the rest has the same number.
so far this is my code:
using System;
using System.Collections.Generic;
using System.Text;
namespace LotteryGenerator
{
class RandomNumberGenerator
{
Random randomGenerator;
int[] randomStorage = new int[6];
public RandomNumberGenerator()
{
}
public int RandomGenerator(int randomNumber)
{
for (int a = 0; a < randomStorage.Length; a++)
{
for (int aa = 0; aa < 6; aa++)
{
randomGenerator = new Random();
randomNumber = randomGenerator.Next(1, 20);
randomStorage[aa] = randomNumber;
if (randomStorage[a] == randomNumber)
{
randomNumber = randomGenerator.Next(1, 20);
randomStorage[a] = randomNumber;
}
else
{
}
}
Console.WriteLine("{0}", randomStorage[0]);
}
return randomNumber;
}
}
}
|
|
|
|
|
Try calling new Random() just once, in your constructor. It could be that every time you create a new one it resets the seed.
I hope you realise that hamsters are very creative when it comes to revenge. - Elaine
|
|
|
|
|
Your right...when i transferred it outside the for loop it stops pushing the same number. But there are still two same numbers that are in the array..maybe changing something in the validation could solve the problem.
Thanks.
|
|
|
|
|
Random means that sometimes you will get the same number twice!
I hope you realise that hamsters are very creative when it comes to revenge. - Elaine
|
|
|
|
|
Ok then..I understand...if that's the case then i should really do something to prevent that..
|
|
|
|
|
If you don't supply a seed value to the RNG when you create it, it uses the current timer value, down the the millisecond it supplies, as the seed. Since your code (needlessly) creates a new RNG every interation of the loop, multiple iterations are using the same timer value as their seed, and hence, comming up with the same stream of "random" numbers.
All you do is create the RNG once, in the class' constructor or some other appropriate place that is executed only once. You don't need to create a new RNG every time you need a new random number.
Also, the RNG does not guarantee that each number in the set of returned number will be unique. You'll have to wrap it in an implementation that keeps track of the numbers already returned and check to see if the next number returned is already in the set and grab a new number if it is. This will, of course, get slower and slower as the number of unique numbers you use gets larger and larger.
|
|
|
|
|
If your application requires different random number sequences, invoke this constructor repeatedly with different seed values.
Give the constructor if the Random class a seed. Any changing number will do, e.g. the sum of the hours and minutes of the current date.
Enjoy
Where?
|
|
|
|
|
Ok. I'll post the code that still stores two same numbers into the array.
Here's the code:
using System;
using System.Collections.Generic;
using System.Text;
namespace LotteryGenerator
{
class RandomNumberGenerator
{
Random randomGenerator;
int[] randomStorage = new int[6];
public RandomNumberGenerator()
{
}
public int RandomGenerator(int randomNumber)
{
randomGenerator = new Random();
for (int a = 0; a < randomStorage.Length; a++)
{
for (int aa = 0; aa < 6; aa++)
{
randomNumber = randomGenerator.Next(1, 50);
randomStorage[aa] = randomNumber;
if (randomStorage[aa] == randomNumber)
{
randomNumber = randomGenerator.Next(1, 50);
randomStorage[aa] = randomNumber;
if (Array. )
{
randomNumber = randomGenerator.Next(1, 50);
randomStorage[aa] = randomNumber;
}
}
else
{
}
}
Console.WriteLine("{0}", randomStorage[0]);
}
return randomNumber;
}
}
}
Please leave a comment about what should i do to solve the minor problem. I'm not asking for the codes as i'll be the one to do it. Thanks.
|
|
|
|
|
Don't instantiate the Random in the method!
class RandomNumberGenerator
{
Random randomGenerator<big> = new Random()</big>;
or, better yet
class RandomNumberGenerator
{
private static readonly Random randomGenerator<big> = new Random()</big> ;
|
|
|
|
|
Ok..Thanks
One question, what if i deleted readonly? Will there be any changes?
|
|
|
|
|
|
Given you are writing a lottery number generater, there is an easier implmenation to select numbers:
1. Create a list of int, containing the numbers in order you want to select from (e.g. 1-50)
2. Create a random position number (starting in the range 0-49 in my example),
3. Take the value at the random position and remove from the list
4. Reduce the random position range by one as you have removed from the source list
5. Rinse and repeat steps 3 & 4 until you have enough numbers to fill your lottery card...
You can refactor this to work without the list, but it will be harder to understand
|
|
|
|
|
|
The seed is the number that you pass in the constructor. E.g.,
randomGenerator = new Random(1); will result in a different list of "random" numbers than this;
randomGenerator = new Random(2); Enjoy
Why?
|
|
|
|