|
Structures are allocated on the stack and not on the heap as classes.
Write the following code instead, it does the same trick:
C s = new C();
using (s)
{
s.clan = 1;
}
Ami
|
|
|
|
|
Ami Bar wrote:
Structures are allocated on the stack and not on the heap as classes.
That is correct in this context - I just didn't know that variables declared in using nlock need to be read-only.
BTW, what exactly "read-only" really means in C#? It does not have const methods like C++.
Whatever... Thanks for your answer
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
|
Good day all.
While attempting to use the ListView column Textalign property to 'Center' text with in the first column of my Listbox, it always uses the Left text align variable. I have a three column ListView. The sub items of this List accepts and aligns the text within the other columns 'Centered'.
Thank you in advance for your assistance.
Have a great coding day.
Regards,
Tony D. Abel
|
|
|
|
|
Please check all your columns and there TextAlign property in your listview control. And make sure the value of TextAlign property is 'Center'.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
hi, i've added user control onto my main form. but when i run my program, i realise it eats up a lot of resources. my com becames very lag. what's the problem?
Chris
|
|
|
|
|
What sort of user control that you are using ? i mean what it does ?
Sreejith Nair
[ My Articles ]
|
|
|
|
|
i've this main window form where it contains 4 user control. each of this user control connects to the database. after i added these user control onto my main form and run my program, my com became very lag.
Chris
|
|
|
|
|
Try to create a class which do database communication insted of user controls. And try to get the reference of class which have the implimentation part of data access into your user control.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
ok i try tt. thanks
chris
|
|
|
|
|
hi, i've managed to put the database connection coding into a separate class.
namespace WindowsApplication2
{
public class db1
{
public OleDbConnection conn;
public string display_SQL;
public OleDbCommand display_cmd;
public OleDbDataAdapter display_adapter;
public DataSet display_ds;
public db1()
{
conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data source =C:\Documents and Settings\Desktop\WindowsApplication2\bin\Debug\mydbms.mdb";
display_SQL = "SELECT * FROM tblYear";
display_cmd = new System.Data.OleDb.OleDbCommand (display_SQL, conn);
display_adapter = new System.Data.OleDb.OleDbDataAdapter(display_cmd);
display_ds = new System.Data.DataSet();
display_adapter.Fill(display_ds,"tblYear");
}
}
i'm not really good in using separate class.so how do we do these same connection into a function in this same class instead of doing it in the constructor? and how do we call that function from a button?
anw is there a wweb site where they teach about windows classes which may assist more??
Chris
|
|
|
|
|
sorry i was wrong. i don't know how to call the function from a different class if i do a database connection in that function and not in the constructor of the separate class?? is it public void connection(){} or ??
|
|
|
|
|
Handle it on button click.
create an object of ur class
Class DBConnection
{
public void Connect()
{
....do ur code;
}
}
Button1_Click()
{
DbConnection DbConn = new DBConnection();
DBConn.Connect();
}
U can pass and return parameters too to this Connect Function;
I hope I am up to ur expection...
Ketty
|
|
|
|
|
hey thanks a lot. but i've got one question let say i've got this form which has a textbox and dataGrid. then i will create a separate class like wat u taught me. if my SQl statement goes like this: "Select * From Table Where Col1 ='" + textBox1.Text + "'";..... how should i pass in the textBox1.Text value to this connection function??
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
db1 a = new db1();<br />
dataGrid1.DataSource = ??<br />
dataGrid1.DataMember = ??<br />
}<br />
Class DBConnection<br />
{<br />
public void Connect()<br />
{<br />
string SQL = "Select * From Table Where Col1 ='" + textBox1.Text + "'";
....do ur code;<br />
}<br />
}
Chris
|
|
|
|
|
In that case
private void button1_Click(object sender, System.EventArgs e)
{
db1 a = new db1();
dataGrid1.DataSource = Connect(txtbox1.text);
dataGrid1.DataMember = ??
}
Class DBConnection
{
public DataSet Connect(String TextVal)
{
DataSet ds = new DataSet();
string SQL = "Select * From Table Where Col1 ='" + TextVal + "'"; //??
....do ur code;
Return ds
}
}
Is that fine now
Ketty
|
|
|
|
|
hi, thanks i managed to do it. but i got another problem.. i'v e got this class.. this is the function
<br />
class test<br />
{<br />
public void test ( string LD )<br />
{ <br />
LD = "haha";<br />
}<br />
}
<br />
class Form1:System.Windows.Forms.Form<br />
{<br />
private void btnConvert_Click(object sender, System.EventArgs e)<br />
{<br />
string date;<br />
cL.CalendarConversion(date);
}<br />
<br />
}
<br />
i can't pass the value of LD from class test to date from class Form1.. why?<br />
Chris
|
|
|
|
|
class test
{
public string test ( string LD )
{
LD = "haha";
}
} // end of class test
class Form1:System.Windows.Forms.Form
{
private void btnConvert_Click(object sender, System.EventArgs e)
{
string date;
test ts = new test();
date = ts.test();
cL.CalendarConversion(date); // date is not null now
}
}//end of class form1
Is this that u wanted?
Ketty
|
|
|
|
|
I have a Form that contains a progress bar. While the form has focus, it works fine, but as soon as it loses focus the progress bar stops working and the form doesn't work until the process is completed. I've tried refreshing the form and the control to no avail. Thanks for any help. My next step is to try to multithread it.
|
|
|
|
|
mrlou88 wrote:
and the form doesn't work until the process is completed
Which process do you mean?
www.troschuetz.de
|
|
|
|
|
Try adding a call to Application.DoEvents() inside your loop.
Regards,
Alvaro
Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we. - George W. Bush
|
|
|
|
|
I would suggest using Delegate and Events to update the status bar based on the events in the process.
Cheers!
<bold>Looney Tunezez
"If you build it....
.....BUGS will come!" -JB
Application.Run(new Form1(this.Dispose())); <--WHAT :wtf::confused::eek:
"Stability. What an interesting concept" - Chris Maunder
<bold>
|
|
|
|
|
i created a control which has a collection of an object which is not control.when i add an object to this collection during design time no code is added to my code page ,i want to know whether controls can be added from designer to a collection or i miss something..?
|
|
|
|
|
It is very difficult to determine what is your problem and what it is you are asking! But I will try to give you an answer.
If you have a control on a form that also has a collection of items (such as a ListBox) you can either add objects at design time or at development time. These, however, are not controls!
Controls (naturally) are added to forms at design time and you can add additional controls at runtime. You can also access the controls you added at design time.
Some controls (like infragistics) also have controls that have control collections. Again, you can add them at design time as well as at development time.
Access of the controls, what control to add, how to access and control them, is dependant solely upon the control itself.
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
mmmmmm...
you know my control uses a colection objects that they are control,during design time i can add,remove and so on and i can see the effects but no extra code is written for them by designer and when i run my project its clear that i loose my collection .i want to know if i have to add some code to my control or collection to force the designer to apply codes to the project itself...
thanks...
|
|
|
|
|
Ah, now the clarity rises!
If you have it ATTRIBUTEd as a collection and it binds successfully with the CollectionEditor (the elipse opens the window to Add and Remove objects from the collection) then it should add the objects for you...in the designer.
However, you also will have to generate the required output so that the source code represents those objects. You should be creating the definitions for each individual object as well as the adding to the control collection in the InitializeComponent() section. So that is going to require hooking into the Changed event so that you can handle those changes in the source. This include removing any objects pulled out of the collection.
You will also probably have to do some reverse population, so that when the editor is closed/reopened you can gather your definitions/properties from the source code so that the designer properly represents the populated collection.
So you would have to generate:
...
MyNamespace.MyItemType {object namein collection};
...
private void InitializeComponents()
{
...
set any properties here that the user changed in the collection editor
MyNamspace.MyControl {theirname} = new MyNamspace.MyControl();
{theirname}.Items.Add({object namein collection});
Good Luck.
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|