|
i'm a newbie in C#. I have a datagrid and I want that when I doubleclick a row to load a new form with textboxes in which I'll have the data from that specific row. how can I pass the data between the datagrid and the new form textboxes?
Thx in advance and I hope I was clear in my request, because my english really sucks )
|
|
|
|
|
hi,
follow the steps below...
a) Write a class that can hold the inputed data(values from textboxes)
b) Make an object of this class in your calling form
c) handle the double click event of the datagrid.
d) In the delegate instantiate the data entry form and open it as modal dialog
e) while instantiating data entry form pass the object of the data class through the contructor(you need to modify the constructor of the data entry form to accept an object of type : data class)
f) Give the "ok" or "close" button in the data entry form a dialog result... say "OK"
g) On click event of ok button populate the data class with the values.
h) in the calling form check for the dialog result right after you call "ShowDialog()" in the data entry form
i) if the dialog result is OK then populate the datagrid with the values in the class object
rest is upto your guess work... and how u can enhance this...
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
|
//Note : before running this code please show some data on datagrid.
//write your code on doubleclick event of your data grid.
//this code is not full. here you will get
//an idea and remaining you have to develop based on your requirement.
//If this is not self explanatory then please let me know that.
//here you will get the point that where you clicked.
Point pt=dataGrid1.PointToClient(Cursor.Position);
//row or coloumn no where you clicked
DataGrid.HitTestInfo hit=dataGrid1.HitTest(pt);
//here i am checking whether i clicked on row header the show the form .use Hittesttype enum to achive your idea
if(hit.Type==DataGrid.HitTestType.RowHeader)
{
Form2 Frm=new Form2();
Frm.ShowDialog();
// you got the idea right.
//use the below line to get data from datagrid or set data to datagrid
dataGrid1[hit.Row,0]="haha";
}
Sreejith S S Nair
|
|
|
|
|
thx a lot, this was very helpful
|
|
|
|
|
hai there,
i have a form with two label control. i need to click on that control. how ? using mouse right. ha ha.
here i need to call the click event programatically without clicking on that control. I won't use any custom event handler here .
Is it possible to control the event triggering through programmatically
Sreejith S S Nair
|
|
|
|
|
Hi,
If you are trying to call the event delegate from any perticular place... say...
you want that when you click on the first label the second lebel controls click event should trigger...
if this is your plan... then you don't need to trigger an event actually... you call the delegate method directly with the necessary parameters... or incase you don't need the parameters send null.
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
if you don't have clear picture of problem and solution please don't reply any queries.
Sreejith S S Nair
|
|
|
|
|
Hold it!
Since your a beginner at this, your problem descriptions will no doubt be vague at times or completely incomprehensible, especially since your English is also not too good. I suggest you cut us some slack...If we can't understand you, we're going to ask questions and make suggestions for further clarification. If you can't provide a clear description of the problem, it's not your place to jump down someone's throat, especially if they are trying to understand and help you...
...the soapbox is now available...
RageInTheMachine9532
|
|
|
|
|
If you're calling this from within a Control , you can call the undocumented protected member InvokeOnClick like so:
InvokeOnClick(label1, EventArgs.Empty); Otherwise, you'll have to P/Invoke SendMessage (see http://pinvoke.net/default.aspx/user32.SendMessage[^]) and send WM_LBUTTONDOWN (0x0201) and WM_LBUTTONUP (0x0202) in sequence using the Handle property of the control for which you want to simulate a click as the first parameter to SendMessage .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for your this mail and your nice suggection. In future also i am expecting the same if i make any mistake.
The main problem is now i have little pressure in my office. So i won't get time to tryout the queries. What normally i will do is, will give little idea that known to me. And if it is wrong i will surly appologies that.
I get into dotnet through book and online material only. So this may happen.
I will try my level beat to avoid this sort of problems.
Sreejith S S Nair
|
|
|
|
|
Hi, I must get a string from a function included into a DLL, imported in a ASP.NET page.
The code:
----
Into a .aspx.cs page:
//def. function included into a DLL
[DllImport("WebUtility.dll", EntryPoint = "getDescr")]
public static extern string getDescr(int id);
//call the function:
string descr=getDescr(123);
---
into the c++ program, the function is definied as:
char* getDescr(int id) {
char* ret=new char[LUNGHEZZA_STRINGA_MEM];
strcpy(ret,oggetto[id].descr);
return (ret);
}
If I throw the application, the server give me the error: System.NullReferenceException: Object reference not set to an instance of an object.
But this error is generated not every time, but random!! some time I can view the string correctly! Why?
Thanks for the help!!!
|
|
|
|
|
First of all, you don't need the EntryPoint property if the entry point is the same as the declared method name.
Second, where is the NullReferenceException getting thrown? It wouldn't be thrown from string descr = getDescr(123); . Perhaps the descr is null and you're trying to call a method on it, but you should always check conditions and not assume anything, such as if an actual reference was returned (value types can never be null unless they're boxed).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
reply 1) there are various funcion into a DLL, so I need an Entry Point
reply 2) into a DLL, descr is NEVER null, I created a function that print out a log file that contain the descr value.
I don't understood because "NullReferenceException" one time get thrown and the next time no!
bye
|
|
|
|
|
Trust me - I know interop in .NET. You don't need to specify the entry point if the method name is the same because the method name is used as the entry point.
I wasn't talking about in your C/C++ DLL - it wouldn't throw a NullReferenceException anyway - that's thrown by the runtime. I was talking about the variable that takes the return value of getDescr called descr . If it's null and you try calling a method on it you will get a NullReferenceException . Assuming that your code "just works" is never a good practice.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi there,
I'm making this application, that need to use some methods from a lib-file. I think that the lib-file i created i VC60, but I'm not sure.
How du I use this file in C#? I can't add it as a ressource. I can't use DLLImport.
The lib-file and a header fil (.h) is the only files I have avalible. What to do???
I found out that I can use the files i VC60 to make an application. I the answer to my question that I have to make some kind of a wrapper class?
|
|
|
|
|
hi,
As far as I know, using the lib and .h file make a DLL(Win32) or a COM component using VS 6.0 and then use it in .NET
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
You mean like a wrapper class.
|
|
|
|
|
So you have some lib file which is created on VC. What you can do is,
use tlbimp.exe (type library importer ).
you will get Visual Studio .NET Command Prompt in your progarmm menu through VisIDE option.
choose - MS Dotnet - Visual Studio .NET Tools -Visual Studio .NET Command Prompt
There you type
tlbimp.exe YourLibfile.lib /out : MyResultentDll.dll /verbose
( if you have YourLibfile.lib in your c drive and you want the resultent .dll on c drive you can simply copy the above syntax and change the file names that you required.
Otherwise give the path and file name of lib file and give the path and name of resultent file.)
/verbose is used to get full output info.
Here you will get a .dll file and use can easily refer this in your project.
Sreejith S S Nair
|
|
|
|
|
I have tried what you are descriping and I get an error that says: "The innput file filaname.lib is not a valid type library"
|
|
|
|
|
That's because a .lib file is used only during binding. If you want to P/Invoke functions, in the API documentation for those functions when it says a function is exported from, say, user32.lib, you actually use user32.dll. The .libs are documented because those are what you actually need to link against when linking your native (i.e., C/C++) application or library.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Do you have any idea what a .lib file is? It's used only for linking during the link step of compiling a native (i.e., C/C++) application or library. They cannot be used in such a way.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
That is strange. If I include the lib-file i C++. It works!
I cannot find any dll file that should contain the source. If I only colud find that my problem would be resolved.
Do you have any ideas, who to find it???
|
|
|
|
|
Like I said, C/C++ use .lib files to link when you're compiling and linking your source. This resolves exports, their relative addresses, and maps them into your code. When executed, your app or library actually binds against the DLL. The .libs are only used during linking and only work in C/C++.
.NET is managed environment, managed by the Common Language Runtime. There is no such linking (at least, not in that way). They are two completely different environments.
I suggest you read-up on .NET at http://msdn.microsoft.com/netframework[^] and get an overview of what actually happens.
If you want more specific information on P/Invoke, see Consuming Unmanaged DLL Functions[^] in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for your answers and your time.
|
|
|
|