|
The easiest way to bind a data grid with an array list (or any object container, for that matter) is to use Update Controls .NET. You can drop an UpdateGrid on your form and implement the GetItems event. This event just returns the array. Then implement GetCellValue to get the values to display. When the user changes a value, the control fires SetCellValue.
Here's an example:
private System.Collections.IEnumerable itemsGrid_GetItems()
{
return _order.Items;
}
private object itemsGrid_RowAdded()
{
return _order.NewItem();
}
private void itemsGrid_RowDeleted(object tag)
{
_order.DeleteItem((Item)tag);
}
private UpdateControls.Forms.ColumnDefinitions itemsGrid_GetColumns()
{
return new UpdateControls.Forms.ColumnDefinitions().
Add("Name", typeof(string)).
Add("Price", typeof(decimal)).
Add("Quantity", typeof(int)).
AddReadOnly("Total", typeof(decimal));
}
private object itemsGrid_GetCellValue(object tag, int column)
{
Item item = (Item)tag;
if (column == 0)
return item.Name;
else if (column == 1)
return item.Price;
else if (column == 2)
return item.Quantity;
else
return item.Total;
}
private void itemsGrid_SetCellValue(object tag, int column, object value)
{
Item item = (Item)tag;
if (column == 0)
item.Name = (string)value;
else if (column == 1)
item.Price = (decimal)value;
else if (column == 2)
item.Quantity = (int)value;
}
|
|
|
|
|
Hello,
Please provide me some inforamation on how windows grapics system and mouse movement is mapped to each other? When we create a GUI using MFC how the mouse movements and MFC control gets mapped?
Plz help me
thanks in Advance
Bil
|
|
|
|
|
[modification @ 10:12 Monday 26th February, 2007]
Moved to the C# forum:
http://www.codeproject.com/script/comments/forums.asp?forumid=1649&select=1912526#xx1912526xx[^]
[/modification]
I am implementing a custom IExtenderProvider derived class so I can dynamically set the following properties on a control:
Required (using an ErrorProvider)
Description (ToolTip)
Errors (using an ErrorProvider)
Caption
I have everything working except for the caption. Ideally, I would like to add a Label control to the form for the given UI element. I know how to draw the label text myself, but that doesn't give me any of the accessability features that I gain when using a label.
The problem I'm running in to is that I can get the label to appear at design time but not at run time. Essentially, when I detect that a new control has been added I try to add a new label control (positioned appropriately) to the parent's Controls array. This works fine at design time but at run time the Parent property of the control I'm extending is null.
I'm trying to do this using an IExtenderProvider so I don't have to create subclassed versions of the UI controls to add a caption. In case you want the background, the project I'm working on needs to allow a dynamically rendered UI based on various pieces of meta data contained in the business object. The business object can be customized by the end-user through an admin interface, so I will never know what fields will be present and what their captions should be until it is time to actually render the screen.
Has anybody done anything similar to this? I've pretty much exhausted the information available on Google, which isn't much beyond creating a simple provider.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Scott
Sorry that it has taken so long to get back to you, but the way to do this is fairly straight forward. In your Set... method, add a handler for the ParentChanged event like this:
txtItem.ParentChanged += new EventHandler(txtItem_ParentChanged); Then, your method will look like this:
void txtItem_ParentChanged(object sender, EventArgs e)
{
TextBox control = sender as TextBox;
string labelText = Get...(control);
LabelExtender(labelText, control);
} Finally, create a method for the label extender:
private void LabelExtender(string labelText, TextBox txtBox)
{
Point loc = txtBox.Location;
Label label = new Label();
label.Name = string.Format("label{0}", Guid.NewGuid().ToString());
label.Location = loc;
label.Text = labelText;
label.AutoSize = true;
label.TabIndex = 0;
label.Size = new System.Drawing.Size(35, 13);
label.Visible = true;
if (txtBox.Parent != null)
{
txtBox.Parent.Controls.Add(label);
}
txtBox.Left += label.Width;
if (txtBox.Parent != null)
txtBox.Parent.Invalidate();
}
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete,
No worries. Since this forum is still rather new, I wasn't sure if it has the same amount of regular "readership" as the other forums.
Between your post and Mike's posts in the other forum I was able to get everything working. (That's actually why it has taken so long to respond...I've been heads-down coding the last two days.)
Your post did point out to me that I was missing an event handler for when the extended control's parent changes, which I have added. Now that everything is working and getting the finishing touches tomorrow, I'm going to ask if I can do an article on this (at least a slimmed down version), which I don't think I should encounter any objections.
Thanks,
Scott.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Cool - I'll look forward to seeing your article.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I am working now on a windows application I have a large number of documents which is suppose to be archived in a folder but the archiving of the documents is to be hidden something like a PST file created for the outlook (store the mails and the attachments). The same way I need to store all the documents I upload using the application.
Will be better if I could have a clue at the earliest.
Thanx in advance.
-- modified at 0:09 Thursday 22nd February, 2007
Regards,Siva
|
|
|
|
|
Hi,
I'm writing an application supporting MDI. In http://www.codeproject.com/useritems/System_File_Association.asp is described how to associate the documents with my program.
I'm still looking for a method to load additional documents into the application via double-clicking the respective file. With MFC this was done using DDE, but DDE doesn't seem to be supported well in .net.
What is the standard way to achieve this in .net?
TIA,
Matthias
|
|
|
|
|
The closest thing to a ShellExecute is this code:
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "yourfile";
p.StartInfo.UseShellExecute = trure;
p.Start();
p.Close();
Hope that helps.
Ben
|
|
|
|
|
See here[^] for an example.
Note that you can always use the WM_COPYDATA message to pass an arbitrary block of data between processes, so the use of the registry is not necessary.
|
|
|
|
|
Hi All,
How I can customize the WinPE to support the Internet Explorer?
Please help me regarding this.
Currently I customized the WinPE with and I am able to launch the firefox on winpe and i can browse the web.
Thanks,
Vamsee.
|
|
|
|
|
Hi all,
Please tell me how to work with ToggleButton
I need to use two buttons- if i select one the other should be desibled,vice versa.
Hope u got my question.-Just a sample Toggle Button.
Please help me.
pashi
prashanth,
s/w Engineer,
Syfnosys.
|
|
|
|
|
I don't see any logic here. You want to have 2 buttons. If you select one button which disables the other one, how do you want to enable it back? And how can it be ToggleButton? You can not click disabled buttons so how does it have to work as ToggleButton?
You would have to enable the other one back (by clicking some other third button, or the same first button again) before clicking it and disabling the first one.
Have you tried using check boxes or radio buttons?
You can also use one button as some kind of ToggleButton by
checking some conditions in the click button method
|
|
|
|
|
Newbie00 wrote: I don't see any logic here. You want to have 2 buttons. If you select one button which disables the other one, how do you want to enable it back? And how can it be ToggleButton? You can not click disabled buttons so how does it have to work as ToggleButton?
You would have to enable the other one back (by clicking some other third button, or the same first button again) before clicking it and disabling the first one.
Have you tried using check boxes or radio buttons?
You can also use one button as some kind of ToggleButton by
checking some conditions in the click button method
I guess you can follow the conventional toggling method with a single button and a related flag variable. click it, flag becomes 1, click it again, flag becomes 0, and act accordingly. Change
some text and appearance for the two states. That's as simple as it can get. Oh, you have to
take care of the initial state also. You know, the default value thing. :->
ASP - AJAX is SEXY. PERIOD.
|
|
|
|
|
Exactly, that's what I meaned writing about one button which could be ToggleButton. The idea with 2 buttons working as ToggleButton wasn't very good.
|
|
|
|
|
Hi everybody,
I'm working on an Excel application with VSTO but I'm rather used to work with ASP.NET. So I would like to know if in Winforms there is an equivalent to the "application_error" function from the global.asax file (in web application) or if I have to realize one by myself ?
Of course the aim is to have an error manager that would catch all thrown exceptions.
Thanks
|
|
|
|
|
Howdy! I came across this new forum and realized that I still have a problem with a Windows Forms project I am toying with. I am creating a quicken like program. The main window creates a MDI child for each account (checking, credit card, and broker). I cannot figure out how to handle the close button. I want the form to just hide itself and remain in the main menu item that I dedicated to keeping the names of the children, so that the user can reselect and open the form again. However, this doesn't work:
private void CheckingAccountForm_FormClosing(object sender, FormClosingEventArgs e)<br />
{<br />
if (e.CloseReason == CloseReason.UserClosing)<br />
{<br />
this.Visible = false;<br />
}<br />
e.Cancel = true;<br />
}
The window is removed from the menu, and I currently have no way to bring it back.
Ideally I would like to remove the close button from the header of the form but leave the other two. I can't see any way to get rid of that button without losing the others.
I may just get rid of the header and add two custom buttons for the other two functions (minimize and full/screen toggle).
Any ideas?
Another pesky problem is that if I click the close button on the main form, it closes the children but stays open, and I gotta click the close buttong again.
Thx.
|
|
|
|
|
I don't know why You are defining The FormClosing method..
If You are using VC++ 2005 and you've placed a button on the form, that you want to close, all you have to do is setting up the Behavior property named DialogResult (you can choose the proper result's value from the checkbox placed on the right of the DialogResult property)..
If user clicks the button, the form closes. The user can open it from main/parent form's menu again.
In order to handle button's click you have to define
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {} method, which you can choose with the button double clicking (in the design form) or with choosing it from the button's events. In abovementioned method's body you can also write code, like this : this->Close(); which will cause closing the form too (the form wich is the owner of the button).
|
|
|
|
|
Thanks anyway, but that isn't it. I am talking about the red X button that you get in the right corner of any form you create where you do not set the ControlBox property to false.
|
|
|
|
|
Hello!
How can I be notified in Windows Forms,
when a hotkey (which I registered with
RegisterHotKey) is pressed. Is there an
event for this?
Alex
|
|
|
|
|
Nope. You have to override your forms WndProc method and look for the message yourself.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
I'm assuming C#, VB, C++ and other languages are suitable for any questions related to WinForms?
Marc
Thyme In The CountryInteracxPeople are just notoriously impossible. --DavidCrow There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith
|
|
|
|
|
Marc Clifton wrote: C#, VB, C++
Already forums for them as there is for database. Could it be this forum is for design issues surrounding WinForms?
Could end up with overlapping issues.
modified 1-Aug-19 21:02pm.
|
|
|
|
|
Richard A. Abbott wrote: Could it be this forum is for design issues surrounding WinForms?
It's going to be hard to ask questions that don't go into code/language related topics as well, so I think we will see a mixture of languages. This, I believe, is what Marc was asking about.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|