|
Heath thanks for your help. I'm just not getting it for some reason. I have read what you typed several times and its just not clickin for some reason.
From what I gather you do whatever you want to with the dataset like i'm doing, then when your done messing around with it you then update it with
OleDbDataAdapter1.Update(dataset);
so based on what i'm gathering from you. I type the following to refesh my comboBox
comboBox1.DataSource = dataset; // update the comboBox
if that is the correc then for some reason its not working.
private void removebutton_Click(object sender, System.EventArgs e)
{
try
{
string strSQL = "DELETE FROM Movie WHERE Title = '" + comboBox1.Text.ToString() + "'";
oleDbDeleteCommand1.CommandText = strSQL;
oleDbDataAdapter1.DeleteCommand = oleDbDeleteCommand1;
oleDbDeleteCommand1.Connection = oleDbConnection1;
oleDbDeleteCommand1.Connection.Open();
oleDbDeleteCommand1.ExecuteNonQuery();
MessageBox.Show(comboBox1.Text.ToString() + " has been removed");
oleDbDataAdapter1.Update(dataset); oleDbDeleteCommand1.Connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Not found");
MessageBox.Show(ex.ToString());
oleDbDeleteCommand1.Connection.Close();
}
oleDbDataAdapter1.Fill(dataset);
comboBox1.DataSource = dataset;
}
sorry Just not understanding this
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
For one, if the item is removed in the data-bound control - which removes it from the DataSet bound to the control - and you update the database, why would you need to update the data-bound control? Think about it - the item is already removed. Why waste the time re-binding when the information is already in sync?
Second, if you want to assign the same DataSet to the DataSource (it's still the same instance), you must reset the binding by first setting DataSource to null then back to the DataSet instance.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok i got it working.
I did used the clear() on the dataset and then refilled it. I'm glad Code Project is around and folks like yourself that give me a hint but not the straight answer. That way I'm forced to learn it.
thanks again,
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Has anyone came up with a solution of how to change the toolbars default color? I noticed there is a toolbar.defaultbackcolor; but that just shows its value. How do you set it. I also read on msdn something about.
private virtual Color BackColor {get; set;} but thats pretty much all it says or i'm not getting it one. I'm assuming you have to override it somehow. I have looked around i see premade classes and all but id really like to know how its done instead of just having someone elses premade stuff. Is it highly complex? if not could someone post a simple example?
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
ToolBar.BackColor is overridden and attributed both with the BrowsableAttribute and EditorBrowsableAttribute to hide it from designer controls (like the PropertyGrid) and source editors. Why? Because it's not used. If you want to change the background color of the ToolBar , you have to handle all the Win32 notification messages by overriding WndProc (experience with Windows messaging will be helpful) or use a third-party toolbar, from which you'll get a lot more options than the simple one included in the .NET FCL (Framework Class Library).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks. I check in on it I knew there had to be a reason it wasn't implemented. Thanks again.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Ok let me explain what i'm trying to do first off
I have 1 form called form1 then i have 2 user controls add and delete.
I have a menu put on forms1 cause i'm using it as my main interface.
I have on the menu a item add record and then remove record.
when i hit the add record i want to bring to focus the add();
and the same thing for if i hit delete i want delete() to bringtofront.
But I don't want numerous instances of the same thing so how do i kill the instances based on the menu selection?
I never want form1 to be killed i just want it to loose its focus based on the menu selection.
So if i have in form1
private database.Add objSearch_notfound;
and under the addmenu
objSearch_notfound = new Add();
Controls.Add(objSearch_notfound);
objSearch_notfound.BringToFront();
objSearch_notfound.Show();
I understand this will bring the add to focus.
I also understand that
Controls.Remove(this);
this.hide();
if put on a button in the add() will kill the add() focus.
But how do i make it do this on the menu?
cause when i click the menu then the add() loses focus so if i did
addmenu()
controls.Remove(this);
this.hide();
it will kill the form1
I thought i could in form1 do this but it doesn't work
Controls.Remove(objsearch_notfound)
objsearch_notfound.Hide();
any clues would be great and hope this is clear. It's kinda hard to explain without showing you the source code.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Showing and hiding user controls or forms will not make dispose of them. Just use a couple of fields in your class to keep a reference to them, the same as the designer does when you design your form:
public class MyForm : Form
{
private Add addControl;
private Delete deleteControl;
public MyForm()
{
addControl = new Add();
deleteControl = new Delete();
}
private void addMenu_Click(object sender, EventArgs e)
{
Controls.Remove(deleteControl);
Controls.Add(addControl);
}
private void deleteMenu_Click(object sender, EventArgs e)
{
Controls.Remove(addControl);
Controls.Add(deleteControl);
}
} This is a simple example, but hopefully gives you some idea that you don't dispose of controls when showing/hiding them, or adding/removing them from the parent's Controls collection property.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
First off thanks this worked perfectly. Well kinda don't know if its just forgotten in your snippet or i'm doing something wrong. In any event. If you don't do addcontrol.BringToFront(); then it simply overlays the other window looking like crap Just something i seen when playing around with.
Thanks again for the help.
but the object ref works great i thought that was how it was done but just couldn't figure it out. thanks again.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
It wasn't "forgotten". Remember, this was sample code. Don't expect a complete solution from sample code: nothing is truly learned then.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
One approach that you could take (if it fits in with your application design) is to make the main form an MdiParent and make the other forms MdiChild forms.
When either choice is clicked the first step each option would take is to issue a CloseAllChildren() call. The logic for the parent form for this method is as follows:
private void CloseAllChildren()
{
System.Windows.Forms.Form[] myChildren = this.MdiChildren;
foreach (Form child in myChildren)
{
child.Close();
}
return;
}
If you children have any valuable resources that they should release, you can add a trap on the Closing Event.
public void Form1_Closing(object sender, System.EventArgs e)
{
... release resources ...
... if user did not save see if they really want to throw
awway their work
e.CloseCancel = true;
}
___________________
Forgoing antagonism and separation, one enters into the harmonious oneness of all things. Lao Tzu
|
|
|
|
|
First of all thankx for a reply. Well, The problem is that as soon as I put a FlashCom control like the Shockwave Flash Object Control that comes with FLASH MX.
As I put the name of the .swf file and play a movie. The .NET Framework Crashes. It Restarts the Framework.
The error it gives is this:
Object Reference not set to an instance of na object.
Well, I am working on a Windows BAsed Application and therefore it is causing much Headache for me.
DO reply and come up with a favourabce Soloution.
Imad
Imad
|
|
|
|
|
This is not helpful at all. The exception message is plain enough to understand: an object reference (i.e., a variable on which you're trying to call a method or access a property) is null , so you get a NullReferenceException . That in itself is not helpful to anyone but you. Debug your code properly, find out where it's happening. If you can't figure it out after that, then post some sample code.
It's like telling a doctor you have pain without telling him/her where it hurts.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
"But Doc, I'm dying here! Fix me!"
Jeremy Kimball
Moderation is for monks. -Lazarus Long
And this, too, shall pass away...
|
|
|
|
|
I want to control windowskey programatically.I saw sendkeys class in C#,but there are no technique in it to control windows key.please tell me any tech,and give me sample code for this.
mughalali
|
|
|
|
|
Throw a simple program together and discover what key data is used:
using System;
using System.Windows.Forms
public class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
protected override void OnKeyDown(KeyEventArgs e)
{
Console.WriteLine(e.KeyValue);
base.OnKeyDown(e);
}
} The left Windows key turns out to be 91, while the right is 92. As I mentioned in the previous post, you can P/Invoke PostMessage and send WM_KEYDOWN (0x0100) to send this key code. See the Platform SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
how i use postmessage in c# to turn on|of the windows left key,give me sample code
mughalali
|
|
|
|
|
Hi,
I am trying to lokalize the "Start Up Folder", in which I need to place/delete files. So that a program will start when Windows starts...
I already tried:
System.Environment.SpecialFolder
..But that didnt exist :S ?
Please help me out - Thanks!
- Up The Irons, Morten Kristensen
|
|
|
|
|
It does exist. I'm not sure what you mean by trying to localize it, but all you need to do to get the Startup folder path is:
string path = Environment.GetFolderPath(
Environment.SpecialFolder.Startup); This will not, however, start when Windows boots. The startup folder is only "used" when a user logs into a Windows session. If you want something to happen when Windows itself starts (i.e., before a user logs in), then you need to write a Windows Service. See the documentation for the ServiceBase class in the .NET Framework SDK for more information and an example. This documentation also contains information about installing Windows Services using the ServiceInstaller and ServiceProcessInstaller classes.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank You!
- Up The Irons, Morten Kristensen
|
|
|
|
|
Hello,
I enabled autoscroll on my tabpage.
Is there a way for me to be notified when the tabpage is scrolled? Which event should I be watching out for?
Also, I am using an animated cursor. It works fine everywhere on my form except when I am over the autoscroll scrollbars of my tabpage. Is there a way for me to change that?
Thanx a lot
-Flack
|
|
|
|
|
The scrollbar is a different control so the cursor you set on your control won't be used for the scrollbar.
To know when scrolling occures, extend TabPage with your own control (you can still add these to a TabControl ) and override WndProc like so:
private const int WM_HSCROLL = 0x0114;
private const int WM_VSCROLL = 0x0115;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_HSCROLL) OnHScroll();
else if (m.Msg == WM_VSCROLL) OnVScroll();
}
protected virtual void OnHScroll()
{
}
protected virtual void OnVScroll()
{
} If you want, add a couple of events that the On* methods fire, and use the Message.WParam and Message.LParam fields to get the relative or absolute positions (which would be handy to pass as EventArgs -derivatives to the event handlers).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanx for the help
Is it possible for me to access the autoscrollbar whenit appears and set its cursor to the one I want?
-Flack
|
|
|
|
|
It's not the "autoscrollbar". It's a normal scroll bar. "Auto" implies a particular behavior. Like any other control, you can encapsulate it and in the .NET 2.0 Framework they will do a better job handling scroll bars. For now, you have to handle all the notification messages using WndProc of the parent control (or using an IMessageFilter for the application, but that can seriously degrade performance if you're not careful). When the mouse moves over the scroll bar control, you can P/Invoke SendMessage to send the WM_SETCURSOR message to the scroll bar. Experience with Windows programming with messages will be very helpful.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Right, I have enabled windows styles on my control. It's taken a bit of time, and it's slightly complicated, but it works.
However, the effects are problematic from the nature of the control, and I can't think of a better way to do it.
Firstly, my control is composed of a number of sub pannels used for mouse over events to detect move and resize actions. This means that for each of those panels I have to run the drawTheme method on their individual device context. And this causes flickering.
I've enabled double buffering, but it's not helping. So i assume that each panel is drawing it's element to the screen.
Is it a speed problem? And is there a way about this?
Secondly.
I have enabled transparency in my theme, but i still can't view the components underneath the corners where the transparency goes straight through to the background image. So i get the corners that are kind of... X-Ray.
Cheers
Cata
Note: the problem with displaying it all came down to the clipping rectangle. If i use anything other than a null pointer, i get nothing.
|
|
|
|