|
|
i have dropdownlist ,it contains countries.
and also i have datagrid ,
if iam changing the country in dropdownlist i want locations of that country in datagrid.
private void dg1_SelectedIndexChanged(object sender, System.EventArgs e)
//code
srinivas
|
|
|
|
|
Simple. If DataTable is bound as DataSource to grid, make as many DataTables as you have countries, and then create HashTable or Dictionary where key is name of the country, and value is DataTable which contains all of the locations for that country. Then, when selection changes for dropdown control, you simply switch DataSource with new DataTable.
|
|
|
|
|
You could try a better subject line in future. Everyone wants someone to solve something here.
If the country list is in the database, you'd store the id of the country in the drop down list values, and then use it to read the locations from the database. If it's a static list, the hashtable idea works just as well.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
load data in dropdownlist and set the valuemember and displaymember properties, then on selectedindexchanged query the database against the id of the country.. and load the data in datatable and bind the table with the grid
|
|
|
|
|
Hi,
Lets say i have an objekt with events ...
<code>
class TestClass {
public event EventHandler TestEvent1;
public event EventHandler TestEvent2;
...
public TestClass() {}
}
</code>
and now i have one Main Form the works with that object...
class MainForm : Form {
TestClass testObj;
public MainForm() {
testObj.TestEvent1 += new EventHandler(testObj_TestEvent1);
testObj.TestEvent2 += new EventHandler(testObj_TestEvent2);
}
void testObj_TestEvent1 (object sender, EventArgs e){}
void testObj_TestEvent2 (object sender, EventArgs e){}
}
and i have a second form the works with the object too, but not mainly. Thats why i start the second form with the instance of the object...
class SecondForm: Form {
TestClass testObj;
public SecondForm(TestClass obj) {
if(obj == null){
throw new ArgumentNullException();
}
testObj = obj;
testObj.TestEvent1 += new EventHandler(testObj_TestEvent1);
testObj.TestEvent2 += new EventHandler(testObj_TestEvent2);
}
void testObj_TestEvent1 (object sender, EventArgs e){}
void testObj_TestEvent2 (object sender, EventArgs e){}
}
My question is now...is the any thing i have to remove or destroy when i close the second form ?
maybe ...remove the added events from the testObj?
|
|
|
|
|
testObj.TestEvent1 -= new EventHandler(testObj_TestEvent1);
testObj.TestEvent2 -= new EventHandler(testObj_TestEvent2);
Of course, it still fires in your main class, because you don't remove it there, an event is a chain, not a single call.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I dont use it like this, the MainForm keep the object and give it to the SecondForm. Because the SecondForm use other methods an events of the object than the MainForm does. The SecondForm close it selft when its done with its work . OK, i should remove the added events from the SecondForm.
But i didnt done this befor and got no execption wich would indicate, that i should do remove the added events.
Is it possible that the GC done that for me ?
-- modified at 7:48 Friday 22nd June, 2007
|
|
|
|
|
Hi,
this is how I understand the situation:
if SecondForm does not remove the events, then SecondForm will not be garbage
collected as long as testObj is alive (which happens to be as long as MainForm
is alive).
Rationale: SecondForm adds event handlers to testObj's events; these handlers
include a "this" reference (pointing to SecondForm) since they call a method
(inside SecondForm) on the specific instance of SecondForm.
Therefore your instance of SecondForm is kept alive by testObj; closing
the SecondForm is irrelevant; Disposing it should lead to an ObjectDisposedException
whenever one of the testObj's events fires (again).
Conclusion: forgetting to remove event handlers can result in keeping a lot
of memory both occupied (i.e. alive) and useless (a form that has been closed
isnt very useful anymore). It resembles a memory leak.
|
|
|
|
|
Hello,
Additionaly to what Christian and Luc where telling you (which was 100% correct of course), I made the expirience that you also have to set the "testObj" to 'null'.
I would suggest to override the Dispose method of the SecondForm, where you remove the delegates and set it null.
All the best,
Martin
|
|
|
|
|
hi frined,
i just implement this code in web aplication, but it is throwing
"System.Runtime.InteropServices.COMException: The server is not operational"
exception, can u please help me to get out of this problem, my management aske me to display the fullname of the loged-in user which is in Active Directory, i don't know how to take this, please help me
|
|
|
|
|
hi all,
can anybody tell me what is the scope of Cookiein the following line System.Net.WebHeaderCollection Cookie=null;
Thanks
vikas da
vikas da
|
|
|
|
|
That depends. If it's a member variable, it's scope is the class. If it's a local variable, the scope is defined by the { } that contain it.
It's just a variable, it has no other scope.
Although it's called 'Cookie', it's actually a collection of headers, not a cookie.
"Contains protocol headers associated with a request or response", according to MSDN.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
In my Program i am getting HBRUSH for particular part of my form using API like BitBlt ,CreateCompatibleBitmap etc.
Now i want to convert HBRUSH to C# Brush object to do remaining painting.
any help will be appeciated
Regards,
Tushar
|
|
|
|
|
Hi,
I never did this, but I suggest you have a look at Brush.SetNativeBrush()
|
|
|
|
|
Hi,How can I create the dll files of my own,how can use them in .aspx.cs
file...can any one simply explain it to me..please give me a sample code...
Hi,Im Razana
|
|
|
|
|
razanabanu wrote: Hi,How can I create the dll files of my own
Use the class library project.
razanabanu wrote: how can use them in .aspx.cs
Add the project that creates the DLL as a reference to the project that contains the .aspx files.
Alternatively, if the DLL exists outside the solution. Use the add reference dialog to find the created DLL.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
Thank you for your help...can you give me a sample code?....
Hi,Im Razana
|
|
|
|
|
There is no code to give you a sample of. It is all in the settings and project types you choose in Visual Studio.
To create a basic DLL, create a project of type Class Library.
To use that DLL in another project in the same solution use "Add Reference..." (right click on the project in the solution explorer to get that) and choose the project from the dialog box.
I think ASP.NET projects are slightly different, but off the top of my head I don't recall what you need to do.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
So its i C# forum
I think you are asking about creating dll of WEB APPLICATION
By Publiching the WEB application you can create a precompile resources
What you want to do by creatng the dll of WEb application ?
Any other dll can be used in your application by simply clicking right click and
Add referennce then add your dll by browsing your machine
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Thank you sandeep.
Hi,Im Razana
|
|
|
|
|
Hi Razanabanu,
here is the code structure that is to be used to create your own dll file.
using System;
//other references
namespace sampledll
{
public class dllfile
{
public static void <function_name>()
{
// your code goes here
}
}
}
for example if this files name is dllfile.cs
then use the following compilation format
>csc /t:library dllfile.cs
this would generate dllfile.dll
Important point to be noted
1. dont use main function. a dll file should not have an entry point.
2. always use public static attributes for the functions.
If you can DREAM it
you can DO it
Natarajasivan D
|
|
|
|
|
Thank you friend,I will try your sample code.
Hi,Im Razana
|
|
|
|
|
Natarajasivan wrote: always use public static attributes for the functions.
That is bollox!
You can put what ever interfaces, classes, structs, etc. you want in there. You are not limited to static methods. You do not have to call your class after the DLL name.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
you need to open a library project and rebuild it
|
|
|
|