|
A CheckBox is not actually used in a DataGridBoolColumn . The class uses ControlPaint.DrawCheckBox to draw a checkbox in the appropriate state.
A good way is - if you're binding DataSet s or DataTable s (which actually contain the row data in a DataSet - is to handle the DataTable.RowChanged event. The DataRowChangeEventArgs gives you information about the DataRow that was changed, though not the exact column that was changed. When this event is fired, though, just check the boolean columns in your handler and do whatever action is appropriate.
A more abstract implementation - to handle cases when you bind ADO.NET data sources or typed lists (any IList or IListSource implementation) is to get the CurrencyManager for the control and handle the ItemChanged event:
private void WatchForChanges()
{
CurrencyManager cm = (CurrencyManager)dataGrid1.BindingContext[
dataGrid1.DataSource, dataGrid1.DataMember];
cm.ItemChanged += new ItemChangedEventHandler(
this.CurrencyManager_ItemChanged);
}
private void CurrencyManager_ItemChanged(object sender,
ItemChangedEventArgs e)
{
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I print 6x4 inch pictures using graphics.DrawImage(),it should work well in most of papersize. But if I select some papersize such as 17x11, 8k and B4,it can't print correct size pictures. I using A4 paper to print and only modify papersize,and I think it should can print size picture. I don't know what's the matter.
thank you.
|
|
|
|
|
In MS SQL Server, it's got an attacth and dettach database, so i want to write a programme to do that, but i do not know where to start.
Thanks
Rock Throught The Night
|
|
|
|
|
Use a SqlCommand to execute them, just like you'd type them in a command parser (like the Query Analyzer or osql.exe). Use a SqlConnection that specifies the 'master' database as the 'Initial Catalog', however. The 'master' database must always exist, otherwise you can't do anything, so it's a good database to attach to when running commands like that.
A simple example (without any error checking, like seeing if the files actually exist first):
public void AttachDatabase(string name, string mdfFile, string ldfFile)
{
using (SqlConnection conn = new SqlConnection(
"Data Source=.;Initial Catalog=master;Integrated Security=SSPI"))
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "exec sp_attach_db @dbname, @filename1, @filename2";
cmd.Parameters.Add("@dbname", SqlDbType.NVarChar, 128).Value = name;
cmd.Parameters.Add("@filename1", SqlDbType.NVarChar, 260).Value = mdfFile;
cmd.Parameters.Add("@filename2", SqlDbType.NVarChar, 260).Value = ldfFile;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
} See the documentation for the sp_attach_db and sp_detach_db stored procs, as well as the SqlCommand.Parameters collection property for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thank you very much.;)
Rock Throught The Night
|
|
|
|
|
I need to implement a delete FileDialog, which looks exactly like OpenFileDialog, only the button is delete button.
What the easiest way to do that without inventing the wheel all over again.
Best Regards.
Anat.
|
|
|
|
|
There really isn't an easy way, and this will most likely be easiest in a mixed-mode Managed C++ project.
First of all, you need to P/Invoke either the GetOpenFileName or GetSaveFileName APIs, which the OpenFileDialog and SafeFileDialog components already do for you. But you must do it because you must fill-out your own OPENFILENAME struct, which must have certain fields set, as well as the hook procedure (depends on the flags you specify, one of which must be OFN_ENABLEHOOK (32)). You must P/Invoke the SetWindowText and any other APIs (like FindWindow , EnumChildWindows , etc.) to help you find the "OK" button (and for localization, don't assume it always says "OK"). This is so that you can change the caption to "Delete".
You call these from your hook proc you specified in the OPENFILENAME structure when you receive the WM_INITDIALOG (272) message. You also should handle the CDN_FILEOK (-606) message and at that point delete the file.
There's a lot to understand, so I recommend you read about the GetOpenFileName [^] and/or GetSaveFileName [^] (you're modifying the behavior, so it really doesn't matter which you use) in the Platform SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you.
I didn't thought of using managed c++. It's a great idea.
I'll try it.
Best Regards.
Anat.
|
|
|
|
|
What is wrong in this code line? (just 1 version of the following 3 used, of course)
m_Data = new Int16[ 36000000 ]; // this functions properly
......... BUT:
m_Data = new Int16[ 37746657 ]; // this results in "System.OutOfMemoryException"
......... AND:
m_Data = new Int16[ 38000000 ]; // this functions properly
So far I found two array size ranges where things go wrong; here are the min/max sizes at the edges of the strange ranges:
37746655 ... 37748726 (0x23ff7df ... 0x23ffff6)
25163743 ... 25165814 (0x17ff7df ... 0x17ffff6)
Please note the similarity of the least 5 digits in the hex representation.
What kind of effect is this?
Regards, rk.
(using .NET 1.1)
|
|
|
|
|
noizy wrote:
What kind of effect is this?
That is weird, I get the same. Sorry, I am not much help, but when I first saw your post I thought you must have done something wrong but not realised it.
That is very odd.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
Hi Everyone!
I was wondering if there is _any_ way to make fance menu images in a context menu. I tried all day long, just to discover http://support.microsoft.com/?id=827043. Unfortunatly they don't tell you about a workaround. Is there really absolutly NO way to make menu images in context menues (apart from dotnetmagic which is no longer free)?
Thanks in advance,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
|
Unfortunatly it does not. The Microsoft link I added describes a .net bug that makes it impossible to set OwnerDraw true in ContextMenu instances. The article works fine for main menus, but not for context menues.
Thanks anyway,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
gek_at wrote:
I tried all day long, just to discover http://support.microsoft.com/?id=827043.
That is a very specific condition, not even relating to images, but menuitems disappearing from the contextmenu. From your question it appears you have a more general problem. I use my ownerdrawn menuitems interchangebly between a mainmenu and a contextmenu and havent had such problems.
Perhaps describing your problem in more detail would be helpful, then we could help you perhaps, but a bunny rabbit came to me in a dream and tells me you didnt multiply the height of the menuitem with item index, and hence your offsets are wrong in the DrawItem event.
top secret xacc-ide 0.0.1
|
|
|
|
|
Hi!
Thanks for your anwer. I did something similar like in this article. The comment there points to the MS bug report, hence I thought it might cause the problem.
Here's my MenuItem Subclass. It's based on the Dr. GUI article from here.
<br />
<br />
using System;<br />
using System.Drawing;<br />
using System.Drawing.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace SharpPrivacy.SharpPrivacyTray {<br />
<br />
System.Windows.Forms.MenuItem {<br />
private Icon icon;<br />
private Font font;<br />
<br />
public ImageMenuItem(string text) : this(null, text) {}<br />
<br />
public ImageMenuItem(Icon icon) : this(icon, "") {}<br />
<br />
public ImageMenuItem(Icon icon, string text) : base(text) {<br />
makeReady(icon);<br />
}<br />
<br />
public ImageMenuItem(Icon icon, string text, EventHandler onClick) : base(text, onClick) {<br />
makeReady(icon);<br />
}<br />
<br />
public ImageMenuItem(Icon icon, string text, MenuItem[] items) : bas e(text, items) {<br />
makeReady(icon);<br />
}<br />
<br />
public ImageMenuItem(Icon icon, string text, EventHandler onClick, Shortcut shortcut) : base(text, onClick, shortcut) {<br />
makeReady(icon);<br />
}<br />
<br />
public ImageMenuItem(Icon icon, MenuMerge mergeType, int mergeOrder, Shortcut shortcut, string text, EventHandler onClick, EventHandler onPopup, EventHandler onSelect, MenuItem[] items) : base(mergeType, mergeOrder, shortcut, text, onClick, onPopup, onSelect, items) {<br />
makeReady(icon);<br />
}<br />
<br />
private void makeReady(Icon icon) {<br />
this.OwnerDraw = true;<br />
this.font = SystemInformation.MenuFont;<br />
this.icon = icon;<br />
}<br />
<br />
public void addIcon(Icon icon) {<br />
this.icon = icon;<br />
}<br />
<br />
protected override void OnMeasureItem(MeasureItemEventArgs e) {<br />
base.OnMeasureItem(e);<br />
<br />
StringFormat sf = new StringFormat();<br />
<br />
sf.HotkeyPrefix = HotkeyPrefix.Show;<br />
sf.SetTabStops(50, new Single[] {0});<br />
<br />
if (icon.Height > font.Height) {<br />
e.ItemHeight = icon.Height + 6;<br />
} else {<br />
e.ItemHeight = font.Height + 6;<br />
}<br />
<br />
e.ItemWidth = (int)((e.Graphics.MeasureString(AppendShortcut(), font, 1000, sf).Width) + icon.Width + 5);<br />
sf.Dispose();<br />
}<br />
<br />
protected override void OnDrawItem(DrawItemEventArgs e) {<br />
Brush br;<br />
StringFormat sf;<br />
<br />
base.OnDrawItem(e);<br />
e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds);<br />
if (this.icon != null) {<br />
e.Graphics.DrawIcon(this.icon, e.Bounds.Left + 3, e.Bounds.Top + 3);<br />
}<br />
<br />
sf = new StringFormat();<br />
sf.HotkeyPrefix = HotkeyPrefix.Show;<br />
sf.SetTabStops(50, new Single[] {0});<br />
br = new SolidBrush(SystemColors.WindowText);<br />
e.Graphics.DrawString(AppendShortcut(), this.font, br, e.Bounds.Left + this.icon.Width + 10, e.Bounds.Top + 2, sf);<br />
<br />
br.Dispose();<br />
sf.Dispose();<br />
}<br />
<br />
private string AppendShortcut() {<br />
String s;<br />
s = this.Text;<br />
<br />
if (this.ShowShortcut && (this.Shortcut != Shortcut.None)) {<br />
Keys k = (Keys)Shortcut;<br />
s = s + Convert.ToChar(9) + System.ComponentModel.TypeDescriptor.GetConverter(k.GetType()).ConvertToString(k);<br />
}<br />
return s;<br />
}<br />
<br />
<br />
}<br />
}<br />
<br />
I use the contextmenu together with a tray icon. perhaps thats the problem?
TIA,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
Hi again!
Here's some more sample code that shows the problem (where ImageMenuItem is used):
<br />
using System;<br />
<br />
using System.Windows.Forms;<br />
using System.Drawing;<br />
using System.Reflection;<br />
<br />
<br />
namespace SharpPrivacy.SharpPrivacyTray {<br />
class MenuTest : System.Windows.Forms.Form {<br />
<br />
private NotifyIcon niTrayIcon = new NotifyIcon();<br />
private ContextMenu cmnuTrayMenu = new ContextMenu();<br />
<br />
private ImageMenuItem mnuTest1 = new ImageMenuItem("Test1");<br />
private MenuItem mnuTest2 = new MenuItem("Test2");<br />
<br />
public MenuTest() {<br />
System.Resources.ResourceManager resources = new System.Resources.ResourceManager("SharpPrivacyTray", Assembly.GetExecutingAssembly()); <br />
<br />
Icon iTrayIcon = (System.Drawing.Icon)resources.GetObject("trayIcon");<br />
this.Icon = iTrayIcon;<br />
niTrayIcon.Icon = iTrayIcon;<br />
niTrayIcon.Visible = true;<br />
<br />
this.ShowInTaskbar = false;<br />
<br />
this.WindowState = FormWindowState.Minimized; <br />
this.ResumeLayout(false);<br />
<br />
mnuTest1.addIcon(((System.Drawing.Icon)resources.GetObject("menuClipboard")));<br />
<br />
cmnuTrayMenu.MenuItems.Add(mnuTest1);<br />
cmnuTrayMenu.MenuItems.Add(mnuTest2);<br />
niTrayIcon.ContextMenu = cmnuTrayMenu;<br />
<br />
<br />
}<br />
<br />
[STAThread]<br />
public static void Main(string[] args) {<br />
Application.Run(new MenuTest());<br />
}<br />
}<br />
}<br />
Greetings,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
IIRC i recall something about this happening because the way it create handles. What happens here is the handle of the form is destroyed and hence the commands probably dont reach them.
top secret xacc-ide 0.0.1
|
|
|
|
|
Hi!
Is there any chance of a workaround?
Thanks,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
The only remarkable differences i can see between my version and yours is:
a) I use Image contained in an ImageList.
b) I dont call the base class when overriding those to methods for very specific reasons, namely this prevents someone from "altering" the gfx from an event as the event will not be generated, and secondly, it prevents windows from doing something it shouldnt (u know that WTF? moments). Sometimes as with some methods the base methods should be called.
top secret xacc-ide 0.0.1
|
|
|
|
|
Hi
when I try to go in designer mode. I get an error it says:"An exception occurred while trying to create an instance of 'MyMainClassName'. The exception was "Constructor on type 'MyMainClassName' not found.
My class has the constructor.
I rebuild the project, but nothing is changed.
Please could you tell me what the problem is?
|
|
|
|
|
The designer expects a default constructor iow one without any paramters.
I was in fact writing this just 2 minutes ago:
throw new Exception(string.Format("default constructor expected on {0}", ppa.Type));
top secret xacc-ide 0.0.1
|
|
|
|
|
|
How can I convert a string that contains Ascii-characters to ANSI? In the Windows API there is a function OemToAnsi. How would I do this in C#/.NET?
thanks, Bruno
|
|
|
|
|
|
hi all, i just want to ask for suggestion
i create a windows form program mainform.cs, and in this mainform i created instance of all classes that will be used.
then i have another form that will only be created when user click a button on mainform.
the second form itself have some functionality, when user click on button, it will call a function.
I found doin this(multiple forms) slow down my program 100% instead of just using one mainform and call the function when user click on the button of the mainform directly.
If this is true that C# windows form very slow when i did this, it's very bad right?
i used to program with multiple java frame(window) and it doesn't matter at all.
Is there something wrong i did?
|
|
|
|
|