|
Use datagrid with paging and set the max records for a page 50.get the records from DB put it in dataset or Datatable bind it to grid with paging
Cheers!!
Brij
|
|
|
|
|
// Exception Handling
using System;
using Students;
public class ExceptionHandling {
static void Main(){
// We declare two students object references, but only instantiate one
// Student object; s2 is given a value of null, indicating that it
// isn't presently holding onto any object.
student s1 = new student();
student s2 = null;
// Exception handling is now in place.
try {
Console.WriteLine("Initializing students....");
// this line executes without throwing exception.
s1.Name = "Fred";
// This next line of code throws a NullReferenceException at run time because
// s2 was never initialized to refer to an actual Student object ...
s2.Name = "Mary";
// ... and as soon as the exception is detected by the runtime, execution
// jumps out of the try block -- none of the remaining code in
// this try block will be executed -- and into the first catch block
// below that is found to match a NullReferenceException, if any.
s1.Major = "MATH";
S2.Major = "SCIENCE";
Console.WriteLine("Initialization successfully completed.");
} // end of try block
//Pseudocode.
catch (UnrelatedExceptionType e1) {
// exception handing code fo this type of (hypothetical) exception
// goes here ... but, since our example doesn't involve throwing this
// particular type of exception at run time, this catch block will be
// skipped over without being executed.
Console.WriteLine("UnrelatedExceptionType was detected ...");
} // end of catch (UnrelatedExceptionType e1)
catch (NullReferenceException e2) {
// Here where we place the code for what the program should do if
// a null reference ws detected at run time.
Console.WriteLine("Whoops -- we forgot to initialize all of the students!");
} // end of catch (NullReference Exception e2)
finally {
// This code gets executed whether or not an exception occured; that is,
// whether we made it through the try block without any exceptions being
// thrown, or whether one of the catch blocks was triggered.
Console.WriteLine("Finally");
} // end of finally
// After the finally block executes, control transfers to the
// line of code immediately following block.
Console.WriteLine("Continuing along our merry way ...");
}
}
// This class has the simple name "Student".
using System;
namespace Students
{
public class student {
private string name;
private string major;
public string Name {
get{
return name;
}
set {
name = value;
}
}
public string Major {
get{
return name;
}
set {
major = value;
}
}
}
}
|
|
|
|
|
Well, at first glance, I am not sure why you have your class in a namespace and your main method seems to not be in a namespace. Does that even compile ? If it does, it looks like this will work, if by work you mean to show how a null reference exception works. What is the question/issue ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thank you for answering. I was not sure, I thought you need to initialize namespace for class. However, in main method you link the programmer-define namespace with "using".
|
|
|
|
|
What do you mean 'you' ? You wrote this code, right ? I didn't. Or do you mean it generically ? Are you asking about code you wrote, or code you found somewhere ? What's the question ? Does the code work ? It looks to me like it should. 'using' is all you need to automatically scope an entire namespace. You don't initialise a namespace, that's not possible at all.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I wrote the code. I meant generically, looking for a suggestion, how would you handle this particular case. The code works fine.
I appreciate your help.
|
|
|
|
|
hello all
i want to set up a serial port communication thru the C# application in which the data from the system (the application) would send the data to the microcontroller. the Microcontroller is having the UART interface to accept and send data i believe...
How is this achieved thru C#.net...
Socket programming || Serial port Programming
i awit for u r valuable suggestions
Thanks
|
|
|
|
|
This[^] is the best reply I have ever seen for your question. Please don't repost.
|
|
|
|
|
I'm inclined to agree with you.
|
|
|
|
|
I'm trying to serialize one of my classes: "ShapeRectangle.cs" to a stream using the BinaryFormatter. I feel that I have a good understanding of serialization which is why this problem is confusing me!
When trying to serialize "ShapeRectangle", an exception is thrown saying that one of my other classes: "ShapeManager.cs" is: "..not marked as Serializable". "ShapeRectangle" has no reference to "ShapeManager" except through an event that it is registered as a listener: (PaintRequest). I tried marking the event: "PaintRequest" as [NonSerializable] but the complier won't allow it!
How can I ONLY serialize the ShapeRectangle class without serializing the ShapeManager class?
Thanks,
Richard
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
|
|
|
|
|
|
How would I make an application in C#, that the user cannot close the application with Alt-F4? Any help would be appreciated!
Thanks,
Josh
|
|
|
|
|
Maybe you cant try this, let me know if it works!
[DllImport("user32.dll")]
private static extern ushort GetKeyState(byte nVirtKey);
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
if (GetKeyState(115) > 1 && (GetKeyState(0xA4) > 1 || GetKeyState(0xA5) > 1))
e.Cancel = true;
}
Saludos!!
____Juan
|
|
|
|
|
As long as you let the user exit somehow.
Generally it's better to put up a "Are you sure?" dialog.
Other than that... here[^] is a link to a similar question (which a simple search may have found).
And this[^] one.
modified on Tuesday, December 9, 2008 10:58 PM
|
|
|
|
|
It can be done easily by overriding ProcessCmdKey in your form.
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if (msg.Msg == WM_SYSKEYDOWN)
{
switch (keyData)
{
case System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4:
return true;
}
}
return false;
}
If you need to handle the System menu's close button and / or the X buttonas well then have a look at my Movement restricted dialog form[^] article. It handles all these on dialog forms but it can be applied to any form at all.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I`m frustrated! Okay,I have Windows Application in C# which has Excel Embedded in it via WebBrowser. I can`t overwrite this file with the changes I make cause the file is locked. I tried a lot of things, but this seems to be a know issue. I can save the changes I make to the Excel File by using [Cntrl + S]. What I`m tying to do is have the users click a button which in turn does Cntrl + S. I can`t seem to get this working. Here is the code I`m playing with.
[DllImport("User32.DLL")]
public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam);
public const Int32 WM_KEYDOWN = 0x100;
public const Int32 WM_CHAR = 0x102;
public const Int32 WM_KEYUP = 0x101;
public const Int32 SDown = 0x220001;
public const Int32 SUp= 0x0220001; //0xC0220001
public const Int32 CtrlDown = 0x11D0001;
public const Int32 CtrlUp = 0x11D0001; // 0xC11D0001
private void button2_Click(object sender, EventArgs e)
{
SendMessage(this.Handle, WM_KEYDOWN, 0x11, CtrlDown);
SendMessage(this.Handle, WM_KEYDOWN, 0x53, SDown);
SendMessage(this.Handle, WM_CHAR, 0x7, SDown);
SendMessage(this.Handle, WM_KEYUP, 0x53, SUp);
SendMessage(this.Handle, WM_KEYUP, 0x11, CtrlUp);
}
Or is there anyother way to save the file? All replies are greatly appreciated.
|
|
|
|
|
This is a nasty hack. Can you do a saveas and then close the spreadsheet, delete the old file and rename the new one ? Seems like less of a hack to me than sendmessage is.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I tried that too, the web browser locks up the file. Also I can`t save the changes made to the excel file.
|
|
|
|
|
when I open the property dialog for Internet protocol version 4 (TCP/IP) for any connection, there is a advanced button. If I click this advanced button, another dialog will showup. For the IP setting tabs, I can add or remove IP addess to/from this list box.
Now I want to do same thing programatically. Is there any way to do it?
I tried to add IP address to the registry manually, even it does showup this dialog but I am not able to ping this this newly added Ip address from another machine but When I add IP address manually using this dialog box, it works fine.
Is there any way to copy this same functionalities to add IP address to this box.
Any advice or hint will be appreciated greatly.
Thank you.
|
|
|
|
|
Maybe you will find the IP Helper API useful. link[^]
led mike
|
|
|
|
|
when i click X button on form, i need to show dialog YesNoCancel.
how to detect exit event for show dialog?
please give hint or tip to me
thank so much...
|
|
|
|
|
Handle the dialog form's Closing event. You can put up your Yes/No dialog in there.
|
|
|
|
|
Hello
Since month now I'm working with WORLD coordinate to display them on a Picture Box using a Graphics
I was making the ofsetting and scaling (manualy) because I never understand the documentation provided for the TransForm matrix
I hope that some specialist will help me to understand how to set a matrix to display an image having
OfsetX
OfsetY
scaleX
scaleY
And taking care that Y coordinate of an image are inverted from the real world
Thanks for any help
Olivier
|
|
|
|
|
You should take a look at this site[^].
What you're trying to do would result in this 3x3 matrix:
[ scaleX 0 0 ]
[ 0 -scaleY 0 ] [ OffsetX OffsetY 1 ]
Multiplying your (x,y,1) coordinate with this matrix should result in what you're trying to do.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you Greeeg
Now I have to find out how to set those values in the GDI Matrix
|
|
|
|