|
I'm still having a problem with my string sorting. I always get the IndexOutOfRange exception during runtime.
How will I solve that?
public static void SortByLastName(ref string[] arrayOfLastNames, ref string[] arrayOfFirstNames, ref string[] arrayOfPlateNum, ref string[] arrayOfType, ref string[] arrayOfYear)
{
Console.Clear();
int vehicleCountInt = 0;
Console.WriteLine("SHOW DATABASE: SORTING BY LAST NAME\n");
using (StreamReader countVehicle = new StreamReader("vehiclecount.txt"))
{
vehicleCountInt = Int32.Parse(countVehicle.ReadLine());
}
using (StreamReader outputLastNames = new StreamReader("lastnames.txt"))
{
int[] b = new int[vehicleCountInt + 1]; ;
for (int i = 0; i < vehicleCountInt; i++)
{
arrayOfLastNames[i] = outputLastNames.ReadLine();
Console.WriteLine();
}
}
int N = arrayOfLastNames.Length;
int W = arrayOfLastNames[0].Length;
string[] temp = new string[vehicleCountInt];
for (int d = W - 1; d >= 0; d--)
{
int[] count = new int[vehicleCountInt];
for (int i = 0; i < N; i++)
{
count[arrayOfLastNames[i][d] + 1]++;
}
for (int k = 1; k < 256; k++)
{
count[k] += count[k - 1];
}
for (int i = 0; i < N; i++)
{
temp[count[arrayOfLastNames[i][d]]++] = arrayOfLastNames[i];
}
for (int i = 0; i < N; i++)
{
arrayOfLastNames[i] = temp[i];
Console.WriteLine("{0}", arrayOfLastNames[i]);
}
}
}
|
|
|
|
|
You don't need ref for those arrays, you're not assigning to them
But wait, how can you be sure that those arrays are long enough?
tip: always tell where you get the exception.
I suspect it happens here: arrayOfLastNames[i] = outputLastNames.ReadLine();
Since there is no guarantee that arrayOfLastNames is long enough (its length is unknown)
|
|
|
|
|
Ok..Is there a way on how to solve that problem? I'm thinking of declaring an array that is large enough for me to store those names.
|
|
|
|
|
I hope you aren't asking for a way to declare an array of a given size..
int[] b = new int[vehicleCountInt + 1]; is one such declaration, but probably 1 too big (why are you adding one?)
If you are asking how to assign to an array which is a function parameter, well, ref is used for exactly that purpose, but out may be sufficient. But this "problem" is as trivial as the first.
|
|
|
|
|
Well I'm referring to how will I solve the problem about the uncertainty of the array's size. I've declared 5 text files with 30 data inside. Now what my groupmate did was create a text file and put there the total number of data inside the text files, and that's the vehicleCount .
Now what I'm thinking is declare an array that has a definite size (say 50) which will hold the data inside the text file(the 30 predefined data and the user's additional inputs). Will this solve the problem about the IndexOutOfRange exception?
|
|
|
|
|
Declaring an array to be intentionally too big is not really nice
You could make it a List or read the file all at once and then split on newlines
|
|
|
|
|
Your right...It didn't solve the problem..I'm sticking to the original code that we created (having a text file that acts like a counter).
|
|
|
|
|
|
string strRaw = "Thisisastring";
char[] astrSorted = strRaw.ToCharArray().ToArray();
Array.Sort(astrSorted);
string strSorted = String.Empty;
foreach (char strChar in astrSorted)
{
strSorted += strChar;
}
eto try mo dn tong code nato
|
|
|
|
|
How to enable click event in Grid view, I am using class Libray project plase help.
modified on Wednesday, September 2, 2009 8:54 AM
|
|
|
|
|
Display the Properties tab in VS when focus is on the GridView, and click the Events button. Scroll to the 'Click' event and select the appropriate event; the designer will create stub code and navigate to the function so you can add your code.
|
|
|
|
|
hi,
how can i develop a patch for my win application. whenever i update some portion in my apps and then i have to always give the big setup to my client. it is very time consuming. so anyone can tell me how can i develop a patch for my apps that when i update any portion of apps then i will just create a path and give this path to my client and client will install easily. if is there any way then please tell me how can i do it.
tbhattacharjee
|
|
|
|
|
You can buy tools to do this, which actually do patch the binary.
You can also use winzip self extractor to deploy just the files needed to update an install.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Further to Christian's answer, a patch should only include changed files. If you can identify which files are changed, then the problem of building a patch is solved. If you are thinking of patching a single binary then there a potential problems. It is better to ship each component file in full.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Maybe NetDasm - A tool to disassemble and patch .NET assemblies[^] from here on CP will help. If that one does not suit search the articles for patch, there are several likely articles.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi
I have been trying to make a splash screen for my program in C#, i have tried a couple of tutorials in C# as well .. but to no success . !
i only need a simple figure to diplay for a while and than another form(My main Program ) should appear ..
how can i do this ?
Help will be highly appreciated
|
|
|
|
|
|
I use it like this :
In Program.cs, you can see :
Application.Run(new Form1());
So, I create a new form, call it SplashScreen.
In that form I create a timer, for example 3s.
In event splashScreen_Load, I start the timer.
After 3s, I get an event timer_Tick.
In that event, I close the form.
So, change the line in Program.cs to :
Application.Run(new SplashScreen()); // will show for 3s, then closed
Application.Run(new Form1()); // after that, Form1 will show.
|
|
|
|
|
First add a form and name it as splashForm and then on that form remove the border and place a picture box which contains a suitable image.
Include using system.thread;
now in the main form(Form1)
public Form1()
{
thread = new Thread(new ThreadStart(SplashForm));
thread.Start();
}
private void SplashForm()
{
SplashForm newSplashForm = new SplashForm();
newSplashForm.ShowDialog();
newSplashForm.Dispose();
}
private void Form1_Load(object sender, EventArgs e)
{
thread.Abort();
}
I hope this helps you...
|
|
|
|
|
Thanks A zillion evry one !!! its done
|
|
|
|
|
I need to "highlight" (e.g. make it bold) one word in a whole string used as a value in a cell. Is it possible?
I am using DataGridView, DataGridViewRow and DataGridViewTextBoxCell classes in my application.
Here is the snippet of the code:
DataGridViewRow aNewRow = null;
foreach (MatchData aMatchData in aSeasonData)
{
aNewRow = new DataGridViewRow();
DataGridViewTextBoxCell aCell = new DataGridViewTextBoxCell();
aCell.Value = aMatchData.Date;
aNewRow.Cells.Add(aCell);
aNewRow = new DataGridViewRow();
DataGridViewTextBoxCell aCell = new DataGridViewTextBoxCell();
aCell.Value = aMatchData.WhoPlaysWho;
aNewRow.Cells.Add(aCell);
aCell = new DataGridViewTextBoxCell();
aCell.Value = aMatchData.Result;
aNewRow.Cells.Add(aCell);
this.myListOfMatchesGridView.Rows.Add(aNewRow);
}
where myListOfMatchesGridView is of type DataGridView.
And according to the result stored in aMatchData.Result (e.g. 2:1 or 4:2) I need to make the winner team (stored in WhoPlaysWho) bold e.g. if the match was Legends vs. AllStars and the result was 3:1 for Legends the displayed output in the specific cell should be Legends vs. AllStars.
Please, give me a hint how to achieve this. From all I read about DataGrids I know how to change the font for the whole cell but so far I was not able to get an information how to change the font only for one word in a whole string (and use different font for the rest of the string) i.e. how to use two (or more) different fonts in one single cell.
|
|
|
|
|
AFAIK, you can't make the text partially bold. You could go for owner-drawing[^], and draw the text manually.
I are Troll
|
|
|
|
|
Thanks for your answer, although not the one I expected
Meanwhile I got another idea - what about using a rich text box as a grid cell? Is there any possibility to make use of it?
|
|
|
|
|
cuker1 wrote: what about using a rich text box as a grid cell?
Yes, it should be possible to use any .NET control[^] within that DataGrid
"Writing code has a place in the human hierarchy worth somewhere above grave robbing and beneath managing."
--Gerald Weinberg
|
|
|
|
|
Dear All,
I have one data grid in this I am using Dropdown Box, i.e. fine I can see the data but when I selecting the data in Drop down box it's not reflecting in DataGrid.
Can you plz help me.
Thanks
|
|
|
|