|
Thanks very much Pete. Unfortunately upgrading to .NET 3.0 isn't really an option (I'm writing plugins for a .NET 2.0 app) but I'll give StylesSheetManager a go. Cheers!
Keiron
|
|
|
|
|
Hi.
I'm new to ADO.NET, and clearly this question has been asked in different forms before, but nothing I'm reading is working. I'm writing a little sample Windows Forms app that is supposed to display the contents of a table in a database. I've got a simple "add row" button to add a new row, and I'd like to see my DataGridView show the changes when the row is added. The row gets added, but my DataGridView doesn't show it. Shouldn't I be able to register for an event that is fired when my database is updated (or is my DataSet?).
I've tried calling EventsTableAdapter.Update, EventsBindingSource.ResetBindings, DataGridView.Refresh... all to no avail.
Relevant source code to follow...
public partial class Viewer : Form
{
private long m_NextEventID = 1;
public Viewer()
{
InitializeComponent();
}
private void Viewer_Load(object sender, EventArgs e)
{
this.eventsTableAdapter.Fill(this.dDBDataSet.Events);
}
// called on button click, to add a new row to my database.
private void m_NewEasyEntryButton_Click(object sender, EventArgs e)
{
this.eventsTableAdapter.Insert( m_NextEventID++, DateTime.Now,
DateTime.Now, false, 1, "Wrong Number", "This is a test");
// not working?!!
this.eventsTableAdapter.Update(this.eventsTableAdapter.GetData());
this.eventsBindingSource.ResetBindings(false);
this.m_DDBGridView.Refresh();
}
}
private void InitializeComponent()
{
...
this.eventsBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.dDBDataSet = new DiagViewer.DDBDataSet();
this.eventsTableAdapter = new DiagViewer.DDBDataSetTableAdapters.EventsTableAdapter();
this.m_NewEasyEntryButton = new System.Windows.Forms.Button();
this.m_UpdateNowButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.m_DDBGridView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.eventsBindingSource)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dDBDataSet)).BeginInit();
this.SuspendLayout();
//
// m_DDBGridView
//
this.m_DDBGridView.DataBindings.Add(new System.Windows.Forms.Binding("Tag", this.eventsBindingSource, "ID", true));
this.m_DDBGridView.DataSource = this.eventsBindingSource;
//
// eventsBindingSource
//
this.eventsBindingSource.DataMember = "Events";
this.eventsBindingSource.DataSource = this.dDBDataSet;
//
// dDBDataSet
//
this.dDBDataSet.DataSetName = "DDBDataSet";
this.dDBDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
//
// eventsTableAdapter
//
this.eventsTableAdapter.ClearBeforeFill = true;
//
// m_NewEasyEntryButton
//
this.m_NewEasyEntryButton.Location = new System.Drawing.Point(104, 310);
this.m_NewEasyEntryButton.Name = "m_NewEasyEntryButton";
this.m_NewEasyEntryButton.Size = new System.Drawing.Size(75, 23);
this.m_NewEasyEntryButton.TabIndex = 1;
this.m_NewEasyEntryButton.Text = "Easy Entry";
this.m_NewEasyEntryButton.UseVisualStyleBackColor = true;
this.m_NewEasyEntryButton.Click += new System.EventHandler(this.m_NewEasyEntryButton_Click);
}
|
|
|
|
|
The quickest solution is to call "this.eventsTableAdapter.Fill(this.dDBDataSet.Events)" after you insert the row. But this causes the entire grid to refresh, loosing the users scroll position and selection in the process.
The problem is that the row gets added to the database, but is not added to the table adapter. The Fill method reloads the data from the database into the table adapter.
The things you tried weren't working for various reasons. The Update method writes the changes that you just made to the database. It doesn't load changes back from the database. ResetBindings and Refresh didn't operate on the table adapter itself, which is what lacked the up-to-date data.
There may be a more complex solution to force the table adapter to load just the inserted row, but I don't know of it.
As an alternative to data binding, you might want to consider http://updatecontrols.net. These controls keep themselves up-to-date as your data changes. They don't bind directly to the database. Instead, they observe changes in your own data objects.
|
|
|
|
|
Dear RabidHamster,
Thanks very much for your timely, well-written, and complete response. I finally tried the Fill method, and deduced what was going on. I understood everything you said (and updatecontrols.net looks interesting!), but I feel I have to ask my question a little more deeply.
Here's my bigger-picture problem. I want to use a database as a repository for diagnostics from my application (essentially like a log file -- on steroids). This will be updated by multiple processes, possibly distributed on a network, and I'd like to view it both "live," as the data comes in, and in an "analysis mode" where I have more sorting and filtering capability.
I suppose I'll end up using a DataReader to do the "live" viewing, since it's lightweight and faster, and then I'll build a console window of sorts around that. I'll use a data-bound DataGridView of some sort to do the analysis features, which can be done on "snapshots" of the database. But even for the "snapshot" mode -- and especially for the "live" view, I want any UI to have the ability to know about changes to the database, since it's the central repository of information.
Are you really saying there's no built in event mechanism that I can tap into that responds to changes to the database itself? Am I going to have to implement some sort of polling mechanism to check for changes -- and maybe fire those events myself? (and if so, what do I check for?)
Thanks again.
|
|
|
|
|
Ummm... I think I might have found the answer to my problem:
http://www.codeproject.com/cs/database/chatter.asp
|
|
|
|
|
Hi,
I want some instructions in converting existing C# Windows Application to C# Web Application..
Please post your replies as soon as possible.
|
|
|
|
|
If the application has been properly architected it should just be a matter of rewriting the presentation (UI) layer - perhaps with the odd addition elsewhere to support a stateless model of working. If it hasn't been well architected then you are looking at rewriting the whole application.
|
|
|
|
|
Spamming different 10 forums with the same question is very rude and totally unnecessary.
But, the Windows Forms forum is probably the most appropriate place for the question. The answer still doesn't change. If not properly architected, you're looking at a total rewrite, from the ground up.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi all,
I'm hoping someone who knows more about Reflection or the internals of the framework than me can help me out on this one.
I'm working on a very large and complex winforms 2.0 in VB.Net 2.0. We will have quite a few different types of users (eg: Data admin, viewer, editor, business rules manager, etc) and I have been tasked with designing and implementing the security model that handles what each user can do. I intend to base it on our own in-house User, User Role and Permissions oracle 9i tables (ie: a pretty standard security model.)
Someone suggested that rather than having a call to some method like SecurityModule.CheckUserPermission() in every method I could Reflection to find out what method was currently invoked (how?!) and then check the user permission against a table (loaded into memory) which would contain the user's role and therefore whether they had a right to use that method. For example the AddNewEmployee() method might only be available to the "DataAdmin" and the "HRAdmin" roles and all others would not be allowed to execute the method - it would just give them an appropriate dialog.
So does anyone have any thoughts on how to do this? If the above idea is workable can someone point me in the right direction to get started? I've hardly ever used Reflection so am not sure how to go about designing this. Otherwise does anybody have any better ideas for a security model than having to place CheckUserPermission() calls all through this very large app?
TIA for any help/info/suggestions.
Mike
|
|
|
|
|
To get the method you are in, you can use the System.Diagnostics.StackFrame class. You would use new StackFrame().GetMethod().Name . Note however, that it is going to be expensive to use reflection to retrieve permissions for users using Reflection based on the called method, and you are relying on developers remembering to put the necessary "plumbing" code into each method. (Either that, or you are going to be injecting code into every method - and that is a whole different can of worms).
I've done similar to this in the past, and used Extender Providers to control what is available to a user. Shameless plug here - this article http://www.codeproject.com/useritems/AutoEnableUI.asp[^] shows the basics of how to do this. Extending it to use your role model should be fairly trivial.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks Pete - I really appreciate the reply... it gives me somewhere to start at least.
Cheers,
Mike
|
|
|
|
|
If I have a populated dataGrid in visual c++, how can I get values from the dataGrid without going to the underlying dataSet.
Is there a way to use dataGrid->currentRowIndex to reference the row and then return the value from a given column.
Thanks!!
Kim
|
|
|
|
|
Create an object as datarow and the take all the data of ur datagrid column to that object and then refer it..
Regards,
Smart Boy
Mumbai,
(INDIA)
|
|
|
|
|
Hi I am new to programming
Could someone tell me where i could find the simple coding statements for FileToolStripMenuItem_Click? Example i want to write code to "New" "Open"?
IS there a website that can teach me the functions for opening and functionality of menu's
Now this is what i put in =>
Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked
Edit()
Copy()
Please help thanks
Preppy programmer
-- modified at 21:44 Thursday 15th March, 2007
|
|
|
|
|
Maybe this could help you:
http://www.c-sharpcorner.com/UploadFile/ggaganesh/WorkingwithMenusinCSharp11282005004421AM/WorkingwithMenusinCSharp.aspx
|
|
|
|
|
how can i change forms caption and borders?
i wanna have caption in new color and shape with custom title and position and new color for borders
many skin designers dont support rtl layout and i wanna design one myself
|
|
|
|
|
Hi all,
I have a form that contains one button and one textbox, the textbox will take a number that will be passed to another form. I have done this successfully.
The thing is that I need the second form to create a number of pictureboxes = the number received from the first form.
Any ideas?
|
|
|
|
|
If you are dealing with VB.Net the sample approach can give so some insight how to do that. But you should consider defining location, size, back color information for a specific picturebox which you get it from an array. The sample will rename the each picturebox automatically.
<code>
Dim GetNumber as New Int32 = PutHereHowManyYouWant
Dim I as Int32
For I = 1 to GetNumber
Dim NewPicBox as New PictureBox
NewPicBox.Name = "NewPicBox_" + I.toString
NewPicBox.Size = New Size (PWidth(I), PHeight(I))
NewPicBox.Location = New Point (PX(I), PY(I))
NewPicBox.BackColor = color.From.ArgB(P1(I),P2(I),P3(I))
Me.Controls.Add(NewPicBox)
'Here you should create an addhandler and out eventhandler procedure
to control each picture box.
Next
</code>
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
hi JUNEYT
actually I'm using C++.NET
thanks anyway,
|
|
|
|
|
|
|
Hi,
I had some forms that i have created long time ago...
OK now i have created a special form that have three panels - the caption, footer and content. I want to use this form as a base form for my old forms.
The problem is that the sub-controls of the form will not be visible - i had to manualy asign the controls as child of the content panel (that is - adds the controls to the content panels's Controls collection).
Is there a way to make the designer put all controls of the form on its child controls collection, that is on the content panel controls collection.
Thanks, elaj
|
|
|
|
|
Best Freeware Utilities
Unlocker http://ccollomb.free.fr/unlocker
CCleaner http://www.ccleaner.com
Why?: On my 2002 HP XP Home I tried to uninstall Adobe 5 Reader. One .OCX file which was tied to Explorer would not delete. Unlocker usually will unlock the file so you can delete it.
Unable to do so it offered to delete it at the next start up.
After starting up with the file gone I ran CCleaner and it let me remove around 20 entries left by Adobe Reader 5. Now I was able to install the full Acrobat 5 cleanly.
Winaudit http://www.psdu506.demon.co.uk
Why because it is extremely fast. Tells you about your PC and what is going on and shows you error logs.
I have only used it since I got it in MaximumPC magazine disk recently, the URl is a more recent version,
but it has shown me a lot of things which are usually a pain to access.
MicroCenter tech support guy recommended Belarc Advisor, anyone use it?
Now if I can find good explanations for the Event and Error codes, I may be able to keep my PC
running without problems.
Anyone know of a program to compact the registry?
I am also looking for a File Manager to replace Explorer since it keeps ending abruptly, leaves icons for USB drives that have been removed and other weird stuff.
If You could only keep one utility program which would that be?
That would be something to recommend. Thanks.
BSOD lost C: and no recovery disks. No restore program to access D: Retired Ron
|
|
|
|
|
B S O D Profile:
Retired amature Visual Basic 6 programmer
I guess that explains why you think the "Windows Forms" forum is for discussing Utility Programs
led mike
|
|
|
|
|
He tried elsewhere and it didnt work out very well.
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|