|
It's not a problem with casting, but with too many method calls on the stack (hence the StackOverflowException ). Somewhere, you either have an unterminated recursive loop or are too deep in method calls. Examine the stack trace, which should give you some insight into how many calls are on the stack and which one is the offending call.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
That's what I wanted to do, but the call stack is full of the same message:
"Tetour.exe!Tetour.GameBoard.set_polymino(Tetour.Polymino value = {Tetour.OTetramino}) Line 49 + 0xa bytes C#"
when I insert a breakpoint in the GameBoard.polymino set property, it always loop in this property, while I do only 1 call. I think it does not have to loop inside this call because I call this property only one time, and it's just an assignement.
There is no spoon.
|
|
|
|
|
I guess you did say "full of" in a previous thread. Sorry I missed it.
This is an odd problem indeed. Is the original code you posted for the polymino property (which, using the .NET naming guidelines, should actually be Polymino , but I won't get started on that since it's a different topic) correctly declare the same as it is in your code (i.e., is what you posted the exact same thing as what's in your code)?
That's obviously the offending line. Are you sure you're not typing polymino again instead of m_polymino ? This would definitely cause the recursion that's causing the stack overflow.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have found the problem it's in the GameBoard.polymino property.
I wrote:
<br />
public Polymino polymino<br />
{<br />
get { return m_polymino; }<br />
set { polymino=value; }
}<br />
while it was:
<br />
public Polymino polymino<br />
{<br />
get { return m_polymino; }<br />
set { m_polymino=value; }
}<br />
I forgot the "m_" so it made a recursive call to itself and then the stack overflowed. When you talk about "recursive" I checked the code of the property I wrote, and all came from this bad line. And now, the casting works the way I expected: like in C++. I correctly wrote the property in the topic, but not in the project
I hope the engine of this game will be finished soon :p
Thanks for the help Heath!
There is no spoon.
|
|
|
|
|
after binding my table to the datagrid what is an easy way to make a column readonly please
|
|
|
|
|
Set DataGrid.ReadOnly to true . It's important to look at the class documentation, at least for simple things like this.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
that will do the whole grid i only want a column?
|
|
|
|
|
Then explicitly define a DataGridTableStyle with DataGridColumnStyle derivatives matching up with your columns you want to display. For any columns you want to disable editing, set DataGridColumnStyle.ReadOnly to true . For more about tables styles, see the documentation for the DataGridTableStyle[^] class in the .NET Framework SDK. It also includes sample code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
will this work after binding my grid to the table that i am create from the database ie DataTable tbl = LoadData();
MyDatagrid.DataSource = tbl;
|
|
|
|
|
Yes, and you don't need to re-initialize it. You can even add multiple table styles to handle multiple data sources. Again, read the documentation I provided a link for.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
on the case let you know how i get on many thanks
|
|
|
|
|
I cant see where i am going wrong as my loop shows the readonly to be false for every column even though i am setting them to true in my routine and when i loop through the columnsstyle collection i get false for every one???
private void LoadInvoice(DataGrid invoiceJob,ComboBox phaseName)
{
job = new Job();
DataTable list = job.LoadPhasePayers(Convert.ToInt32(phaseName.SelectedValue.ToString()));
invoiceJob.DataSource = list;
AddCustomDatagridStyle(invoiceJob);
foreach(DataGridTableStyle ts in dtgCInvoice.TableStyles)
{
Debug.WriteLine(ts.ReadOnly);
}
}
private void AddCustomDatagridStyle(DataGrid myGrid)
{
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "PhasePayers";
DataGridColumnStyle textCol = new DataGridTextBoxColumn();
textCol.MappingName = "Payer";
textCol.HeaderText = "Payer";
textCol.Width = 250;
textCol.ReadOnly = true;
ts1.GridColumnStyles.Add(textCol);
myGrid.ReadOnly = true;
myGrid.TableStyles.Add(ts1);
DataGridColumnStyle textCol2 = new DataGridTextBoxColumn();
textCol.MappingName = "Net";
textCol.HeaderText = "Net";
textCol.Width = 250;
textCol.ReadOnly = true;
ts1.GridColumnStyles.Add(textCol2);
myGrid.TableStyles.Add(ts1);
DataGridColumnStyle textCol3 = new DataGridTextBoxColumn();
textCol.MappingName = "VAT";
textCol.HeaderText = "VAT";
textCol.Width = 250;
textCol.ReadOnly = true;
ts1.GridColumnStyles.Add(textCol3);
myGrid.TableStyles.Add(ts1);
DataGridColumnStyle textCol4 = new DataGridTextBoxColumn();
textCol.MappingName = "Gross";
textCol.HeaderText = "Gross";
textCol.Width = 250;
textCol.ReadOnly = true;
ts1.GridColumnStyles.Add(textCol4);
myGrid.TableStyles.Add(ts1);
}
|
|
|
|
|
As I said before, do not initialize the table and column styles every time you set your DataSource , which you currently are. You only need to do this once. The way you're currently doing it, you add new column and table styles each time you set the data source, leading to increasing memory consumption, performance degradation, and other unforseen problems with having the same table style added multiple times. Also, how is setting every column's ReadOnly property to true different from simply setting DataGrid.ReadOnly to true ?
The actual problem is most likely because you're DataGridTableStyle.MappingName is set to the table name of the DataSource you're using, which is a DataTable . If you were to actually use a DataSet and set that as the DataSource with the table name set in the DataGrid.DataMember property (which should be the same as the table style you want to use, since you can have more than one table style). If you set the DataGrid.DataSource to a DataTable ,. then IIRC the DataGridTableStyle.MappingName should be an empty string or null (either would work - just don't set it to begin with, though).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
many thanks for persevering with me i got it thanks to you, setting the mapping name to null was the big key and i am glad you spotted my method of setting on every load i was getting tired and difflated at that stage. I am using tables rather than the overhead of a dataset being returned everytime, i have got styles to work with dataset but my little brain was struggling to get it to work with a table now i am off and running again looking for my next brickwall to knock down ))))))
|
|
|
|
|
now it is getting bigger when i switch between design view and code view it is very slow any ideas on how to spped it up
|
|
|
|
|
are you placing any background image to your window?
I usually disable it.
|
|
|
|
|
|
Hi,
I'm writing a program that performs CRC check on sfv files, I've got a method creating an array that's used for filling a listview item, the array is
<br />
public struct LineToCheck<br />
{<br />
public string fileName;<br />
public ulong CRC;<br />
public LineToCheck(string filename,ulong CRC,)<br />
{<br />
this.fileName=filename;<br />
this.CRC=CRC;<br />
}<br />
};
I added a button in my form to start sfv check but since the array is created in a method, I had to create a public static LineToCheck array as global variable and to use .ToCopy(global_array) to fill it, but doing so I've to fix a lenght of array, if I were in C, I would have used LineToCheck *array, and I would have dinamicly add elements.... is there a way to do so in C#??? or to trim an array at inside's method array's lenght?
I don't know if I've been clear..... I hope so, thanks
Paolo
|
|
|
|
|
yes there is a way to use a dynamical array: the class
ArrayList (I guess in System.Collections )...it automatically resizes when necessary, and thus it has no fixed length as a "normal" array in C#....but ArrayList stores the assigned values as objects (aka boxing), so you have to cast when you return something from the ArrayList....
for example:
int i = 5;
ArrayList al = new ArrayList();
al.Add(i);
int storedInt = (int) al[0]; //unboxing
|
|
|
|
|
|
Note that boxing and unboxing is only done when casting value types from an object reference. Casting a reference object does not box or unbox, it simple performs a cast.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
anybody knows about that? please give me one basic example how to use API in C#
nam
|
|
|
|
|
Try this article[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event[^].
|
|
|
|
|
thanks Colin Angus Mackay alot
nam
|
|
|
|
|