|
d@nish wrote: arnold_w wrote:
but the print out says there are zero rows in the table. Why is that?
There has to be some problem with your printing code. Try debug that or post it here.
The code is posted here and the printing code is the second row from the end.
d@nish wrote: arnold_w wrote:
I want to obtain other information about rows and cells (such as their locations), how do I do that?
Try using GetCellDisplayRectangle method.
If I add the following code at the very end:
try
{
Rectangle cellRectangle = dataGridView1.GetCellDisplayRectangle(0, 0, true);
Console.WriteLine("The cell is located at " + cellRectangle.X + ", " + cellRectangle.Y + ".");
}
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine("ArgumentOutOfRangeException. Additional info: " + e.Message);
}
I get an ArgumentOutOfRangeException saying the parameter is outside the valid range. What I missing here?
|
|
|
|
|
arnold_w wrote: The code is posted here and the printing code is the second row from the end
Sorry. I thought you are speaking of printing (hard copy) datagridview. I took a look at your code. Here are some comments:
1. Get rid of binding source and use this:
DataGridView dataGridView2 = new DataGridView();
DataTable dataTable = new DataTable();
dataTable.Columns.Add("My Column");
dataTable.Rows.Add("My Cell Value");
dataGridView2.DataSource = dataTable;
2. What I found from debugging is that unless form is loaded, you don't get the row count. Not sure of reason* but you do get the count in load. So probably if you check for row count in the load event, you would get the correct result.
The second exception is also for the same reason. Put that as well in the Load event and I guess it should work.
*I have posted a question regarding same. You can check that and get to know the reason.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Ok, so I should do something like this instead:
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}
private void Form1_Load(object sender, System.EventArgs e)
{
DataGridView dataGridView1 = new DataGridView();
DataTable dataTable = new DataTable();
dataTable.Columns.Add("My Column");
dataTable.Rows.Add("My Cell Value");
dataGridView1.DataSource = dataTable;
this.Controls.Add(dataGridView1);
Console.WriteLine("There are " + dataGridView1.Rows.Count + " rows in your table.");
}
?
It does seem to work properly.
|
|
|
|
|
d@nish wrote: 1. Get rid of binding source and use this:
DataGridView dataGridView2 = new DataGridView();
DataTable dataTable = new DataTable();
dataTable.Columns.Add("My Column");
dataTable.Rows.Add("My Cell Value");
dataGridView2.DataSource = dataTable;
Ooops, I just discovered that if I don't use BindingSource, I can't use the BindingSource.Filter method. The reason I want a bound form is that I need filter-functionality. Is there a workaround for this?
|
|
|
|
|
There is a RowFilter property (don't remember if it is of datatable.defaultview or of the datagridview). You can use that.
For your other post, check first if the designer file has the code to attach the event handler (+= thing). It depends on the way you create the event.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
The following works great:
DataView dv = dataTable.DefaultView;
dv.RowFilter = ...
Thanks a lot for your help!
|
|
|
|
|
What is the differentiation between Singleton Class and Static Class ?
Thanks...
|
|
|
|
|
A singleton object can be used as a parameter to a method, but a static class can't.
Also, I don't think you can inherit an interface with a static class.
BTW, if you had used google, you could have found this answer a lot faster.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
A singleton can be used in places where you need an instance, so you can still do all that inheritance/polymorphism/etc with it
A static classes can only derive from Object and can not implement interfaces
|
|
|
|
|
All members inside a static class would be static - and hence not available for automatic garbage collection until the app domain is unloaded.
In the case of a singleton class, the instance variables defined in the class will be available for garbage collection.
So singletons have an advantage with respect to memory de-allocation.
There are only 10 types of people in this world — those who understand binary, and those who don't. |
|
|
|
|
|
Hi, I think the difference between the two classes is that
Static Class needs no instance of the object,
while Singleton needs one instance of object and to keep the state.
modified 27-May-14 4:59am.
|
|
|
|
|
Hey how to generate orthogonal partitions. I have a rectangle and i wish to divide it into 8 random partitions and load an image into each partition. can anyone tel me how to do it?
|
|
|
|
|
Hi,
maybe like so:
0. create one random number generator; use only one!
1. choose a random number in the range [0, 2) to select direction (0=horizontal, 1=vertical).
2. choose a random number in the range [0, max) where max is either width or height.
3. repeat 1+2 three times.
You now have 8 rectangles inside the original one.
refinements: impose a minimum width and height for each of them by limiting the range in (2) somewhat.
|
|
|
|
|
Hey wont they superimpose??
|
|
|
|
|
Not unless you want them to. Of course, you'd have to be a programmer to bend the application to your will.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
when you have three (or N) hor/ver lines inside a rectangle, they cut it in 8 (or 2^N) pieces, no matter what (assuming the lines are all different).
|
|
|
|
|
No they don't!
Rectangle:
+---+
| |
| |
| |
| |
| |
| |
| |
+---+
Add three lines (all different):
+---+
| |
|---|
| |
|---|
| |
|---|
| |
+---+
4 rectangles.
Go back to original and add three other lines (all different)
+---+
| | |
|-+-|
| | |
|-+-|
| | |
| | |
| | |
+-+-+
6 rectangles.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
you're right of course, as your ASCII artwork makes abundantly clear.
So the algorithm needs a fix, something like: add any of {(7,0), (3,1), (1,3), (0,7)} hor/ver lines at random but different locations in the rectangle.
Homework: find all solutions for an arbitrary number of partitions.
|
|
|
|
|
I don't do homework.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
refinements: disimpose a minimum width and height for each of them by limiting the range in (2) somewhat. everything as litter.
|
|
|
|
|
I am learning C# and OOP, i just cant understand how a static constructor can be useful... can someone please help me with this?? if possible, can u give a simple example? thank you very much...
Marcus Abrahão
Thank you all very much for your help
modified on Wednesday, January 6, 2010 7:12 AM
|
|
|
|
|
mabrahao wrote: static constructor can be useful
No such thing. static is usefull if you call function without intilizing class. If you intilize, constructor is called
public class Test
{
public Test(){}
public static Color GetColor()
{
return Color.White;
}
}
Color c = Test.GetColor();
|
|
|
|
|
Saksida Bojan wrote: mabrahao wrote:
static constructor can be useful
No such thing. static is usefull if you call function without intilizing class. If you intilize, constructor is called
This turns out not to be the case: Static Constructor[^]
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Thats good to know. I didn't even think it was possible
|
|
|
|
|
Ok, static methods and static class was able to figure out how it works, but not the STATIC CONSTRUCTOR, like so:
public class Test
{
int numTest;
// Static Constructor
static Test()
{
numTest = 5;
}
}
i am reading a book from Andrew Troelsen, about C#, and in the book, he gives a example of a static constructor, but i just could not understand...
anyway, thank u for u help
Marcus Abrahão
|
|
|
|