|
You just need to override the OnPaint[^] method in your form, and draw the lines between each current point, or set of points as appropriate.
Veni, vidi, abiit domum
|
|
|
|
|
Thanks, but I'm so new to C#, and Visual Studio in general, that I would need a little more detail on how to implement it, and what the specific syntax would be, maybe an example. I have been trying to research what you've said, thanks for pointing me in the right direction.
|
|
|
|
|
Davebandit wrote: Thanks, but I'm so new to C#, and Visual Studio in general, that I would need a little more detail on how to implement it, and what the specific syntax would be, maybe an example. There's a How to[^] on MSDN. It's from a section on graphics programming[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks, I'll take a look at it.
|
|
|
|
|
Davebandit wrote: I'm so new to C#, and Visual Studio in general Then maybe, you would be better spending some time working through some of the basics first to get your brain properly attuned to the C# and .NET concepts. Charles Petzold has written an excellent introductory book, titled .NET Book Zero[^], and MSDN offer a set of useful tutorials[^]. Add to that the wealth of information in the CodeProject articles[^] and you have plenty of help.
Veni, vidi, abiit domum
|
|
|
|
|
I am new to C#. I have in mind a nested class structure. First of all. Is this optimal? Secondly, please could someone provide the coded outline of this structure so that I can work on filling and coding the functions.
class Z
class Y
class X
class V
|
|
|
|
|
I'm really short of time on this task.
The task is to take a csv file.
Process a list of x,y specified coordinate points.
Work out the distance between all these coordinate points.
Print results to file
Ta
|
|
|
|
|
Is this for an interview or something?
|
|
|
|
|
yes. got it in one. 10 years since i coded in C# and I underestimated the task.
|
|
|
|
|
Well, time management is part of the interview process for projects like this. Do you really need me to tell you how you've done on that part?
Nobody is going to do your work for you.
|
|
|
|
|
Member 10266494 wrote: short of time on this task
So you left doing your homework assignment until the last minute and expect us to do it for you?
|
|
|
|
|
I would avoid nested classes whenever I can, but that's just my personal opinion.
|
|
|
|
|
This is the third time you have asked what is basically the same question. Nested classes is not the answer, as you obviously don't understand what they are. Take Pete O'Hanlon's advice and go and work through Charles Petzold's free book. You cannot learn how to write good code by repeating the same question in a forum like this.
Veni, vidi, abiit domum
|
|
|
|
|
I don't know where I made mistake.I checked everything !! but this error happened :
"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
thank you in advance.
int i = 1;
int RowNo = 0;
int CellNo = 0;
foreach (DataGridViewRow row in Firstdgv.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (i > Finaldgv.Columns.Count)
break;
Finaldgv.Rows[RowNo].Cells[CellNo].Value = cell.Value;
i++;
CellNo++;
}
RowNo++;
i = 1;
CellNo = 0;
}
|
|
|
|
|
At a guess - and that's about it it can be from that little code - you haven't allocated any rows or columns in the destination DGV, or you are trying to access different sized DGVs.
So when you try to access it's Rows collection via an index:
Finaldgv.Rows[RowNo] Or the resulting DataGridViewRow Cells collection:
Finaldgv.Rows[RowNo].Cells[CellNo] It complains becasue it doesn't exist.
Start this way: put a breakpoint on the if line, and single step through from there - look at the variables as you go, and look for null values. (It may help to "break out" the line assigning the row so that each part to the left of a "." is a separate variable - you don't need to, but it makes it easier to see without complex use of the debugger)
DataGridViewRow row = Finaldgv.Rows[RowNo];
DateGridViewCell cell = row.Cells[CellNo]; And so forth.
PS: Keep an eye on the value of i ...
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
First, the value of i isn't doing anything according to your code, you should be able to remove it and use CellNo instead. Personally I'd move the declaration of CellNo inside the first foreach loop, that way you can also remove the line CellNo = 0; at the end.
int RowNo = 0;
foreach (DataGridViewRow row in Firstdgv.Rows)
{
int CellNo = 0;
foreach (DataGridViewCell cell in row.Cells)
{
if (CellNo >= Finaldgv.Columns.Count)
break;
Finaldgv.Rows[RowNo].Cells[CellNo].Value = cell.Value;
CellNo++;
}
RowNo++;
}
If this doesn't fix your problem (I doubt it will) you need to figure out which of the two indexes is wrong - you can put a breakpoint on, or you could temporarily amend Finaldgv.Rows[RowNo].Cells[CellNo].Value = cell.Value; to:
var tempRow = Finaldgv.Rows[RowNo]
var tempCell = tempRow.Cells[CellNo]
tempCell.Value = cell.Value
And see which line breaks - my initial gut reaction is you have no rows.
|
|
|
|
|
my dear friend ,at first I am so appriciate for your attention.
I revised the code as you said but the error still exist !!
the error happens in the "***" line
when the RowNo=1 error occurs !!
int RowNo = 0;
foreach (DataGridViewRow row in Firstdgv.Rows)
{
int CellNo = 0;
foreach (DataGridViewCell cell in row.Cells)
{
if (CellNo >= Finaldgv.Columns.Count)
break;
var tempRow = Finaldgv.Rows[RowNo]; ***
var tempCell = tempRow.Cells[CellNo];
tempCell.Value = cell.Value;
CellNo++;
}
RowNo++;
}
|
|
|
|
|
When you put a break point on var tempRow..., and inspect the value, what do you find? The thing that stands out to me here is that you have an assumption that Finaldgv has more than one row, and there's no guarantee that this is the case.
|
|
|
|
|
I want to copy Firstdgv rows to Finaldgv rows.So how can I refer to the second,third and... rows in Finaldgv in order to copy the second ,third and .... Firstdgv rows .
I think your assumption is right.but what should I do?
|
|
|
|
|
If you are trying to copy the values from one grid into another (and I'm assuming the second one is empty), then you Add the rows into the other grid.
|
|
|
|
|
thank you my friend it works
thank you ALL
|
|
|
|
|
You're welcome. I'm glad I could be of service.
|
|
|
|
|
<pre lang="css">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class Building
{
int[] list1 = new int[3] { 0, 91, 57 };
int[] list2 = new int[3] { 1, 67, 24 };
int[] list3 = new int[3] { 2, 27, 27 };
int[] list4 = new int[3] { 3, 97, 56 };
int[] list5 = new int[3] { 4, 25, 19 };
int[] list6 = new int[3] { 5, 95, 18 };
int[] list7 = new int[3] { 6, 5, 69 };
int[] list8 = new int[3] { 7, 46, 94 };
int[] list9 = new int[3] { 8, 29, 68 };
int[] list10 = new int[3] { 9, 92, 28 };
for (int i = 0; i < 4; i++)
{
int numberIn = list1[i];
System.Console.WriteLine(numberIn);
}
}
}
I wish to modify this class to allow me to read a csv file in and present an array of arrays that can be returned to a 'stem' class. What is the simplist code that will achieve this please?
|
|
|
|
|
Seriously, you could solve this part with a simple Google search. You really need to learn how to do that part. I'll give you a couple of hints here:
Your data is in a File. You want to Read All Lines from that file.
Once the data is in lines of strings, you want to Split each string into it's constituent parts.
It's that simple.
|
|
|
|
|
csv stands for comma separated values . The lines below your comment do not show any comma between the values, rather spaces. If all of your values are simple numbers and separated by spaces, just read the file line by line and get the contents with string[] contents = line.Split(' '); , then parse each item of contents into an int (int.Parse(...) or int.TryParse(...) ).
|
|
|
|