winforms

Showing the Restore Button without a Maximize button

I want to prevent the user from maximizing the Windows Form to full screen so I have disabled the Maximize button. However, I want to be able to have the user 'restore' the Form. When they click the Restore button I want it to show a different, smaller, minified, form, which will show them a maximize button which will return the use to t...

How do you databind to a System.Windows.Forms.Treeview control?

I'm looking at this control, and it seems to be lacking the standard .net "datasource" and "datamember" properties for databinding. Is this control not bindable? I can write some custom function that populates the treeview from a given data source, I suppose, and embed data objects as necessary, but is that the 'best practice'? Or doe...

WinForms: How to programatically fire an event handler?

i want to programatically invoke an event handler for a control. For example: DateTimePicker dtpLastConsummated; i want to trigger the TextChanged event handler for the dtpLastConsummated, how can i do it? In other languages i would call something akin to: dtpLastConsummated.TextChanged(this, new EventArgs()); but in .NET you can ...

Proper way to get a Winforms UI to block with a dialog until some non-user driven event conditioin?

I was asking about specifics with this approach earlier today here but the confused responses has me wondering if I'm going about this all wrong. So here's the problem. I need to architect a WinForms application that periodically checks a value from some external service. If it is in a certain state the application is supposed to pop ...

Capturing first character on entering edit mode - custom editing control in DataGridView

I'm hosting a custom editing control in a DataGridView, which for the record is a TextBox and Button together in a UserControl. I have inherited from DataGridViewColumn for the new column and DataGridViewTextBoxCell for the new cell. With a normal DataGridViewTextBoxCell, if you press a key when the cell has focus, it will begin edit mo...

Check if a drag&drop is in progress

Hey, Is there any way to check if a drag and drop is in progress? Some method or win32 api which can be checked? I know I can set AllowDrop and use events but it doesn't work in this case. Basically i want to check, with code, if any drag&drop is in progress. ...

Setting the parent of a usercontrol prevents it from being transparent

I've created a simple user control which is manually created with something like MyUserControl ctrl = new MyUserControl(); The control have been designed to have BackColor = Color.Transparent and that works fine, until I set the Parent of the control to a form at which time it turns into the color of the form. Might sound like its tr...

c# (WinForms-App) export DataSet to Excel

Hi, I need a solution to export a dataset to an excel file without any asp code (HttpResonpsne...) but i did not find a good example to do this... Best thanks in advance ...

Add extra column to fill out space in datagridview C#

I have a datagridview which im binding DataTable to. What I want do is add an extra column which will fill out the remaining gap in the windows form. At the moment I only have 3 columns so the width of all the columns is only about half the size of the windows form. ...

Localizing a WinForms Application with Embedded WPF User Controls

The application I'm trying to localize is a WinForms application that has a few hosted WPF user controls (WPF user controls hosted in an ElementHost WinForms control). I use resx files to localize the WinForms, which VS2008 manages quite well. The problem starts when I try to use the LocBaml method to localize the WPF parts. Here's wh...

How do I create a new windows form, and associate it with an already existing thread?

I'm trying to write a chat client in C# and have run into a problem. How it works is that the client polls the server every 1 second to see if there are any new actions to take (for example display a message in a channel, or whatever). The polling is done in a thread of its own. Now, I want the polling thread to open a new MDI form whe...

How do I get a specific drive's icon for any version of Windows?

In a .NET WinForms app, how do I get a specific drive's icon (C:\ for example) for whatever version of Windows the client might be running? ...

How do I extend the client’s timeout in configuration on making a .NET web service request?

How do I extend a smart client's timeout of a web service request in the application configuration? I have a smart client that times out before the server is finished with the request I don't want to make code changes at this stage as deployment is difficult. I was hoping to adjust the configuration for client to extend the timeout per...

How to get control index in WinForms?

I have a Panel with a collection of controls in it. How can I get the index of a specific control when iterating through them? I'm using foreach to iterate, but there's no Index property. Should I use for x = 0... and return x when my match is made, or what? ...

C# Forms App Collections

I'm using .Net 2.0 and this is driving me crazy but there's probably some easy thing I'm not doing that I am now too confused to see. I have an application that has a bespoke collection of objects in it, only the main form should be able to change the contents of that collection and all other forms should be able to read from it. Actu...

How to restrict client control area in a custom WinForms control

Hello, I have a custom control that uses a designer I've inherited from ParentControlDesigner to allow child controls to be dropped. I'm not using any internal designers, just straightforward single-parent stuff. This control draws a "header", so I'm trying to do three things: Have child controls dock to the bottom of the header ins...

Best way to databind a Winforms control to a nullable type?

I'm currently using winforms databinding to wire up a data editing form. I'm using the netTiers framework through CodeSmith to generate my data objects. For database fields that allow nulls it creates nullable types. I've found that using winforms databinding the controls won't bind properly to nullable types. I've seen solutions onl...

Populate Excel with data from LINQ to SQL query.

I am trying to send some data from a LINQ query in C# to an Excel speed sheet using OLE I have a query like this: Var data = from d in db.{MyTable} where d.Name = "Test" select d; I have the Excel OLE object working fine, I just can't figure out how to populate the cells in Excel with the data from the LINQ quer...

How can I add a context menu to a ListBoxItem?

I have a ListBox and I want to add a context menu to each item in the list. I've seen the "solution" to have the right click select an item and suppress the context menu if on white space, but this solution feels dirty. Does anyone know a better way? ...

C# Stop a Treeview selecting one or more TreeNodes

I have a TreeView control showing multiple TreeNodes in an organised heirarchy. I want to stop the user selecting the highest level Nodes (this was achieved by using the BeforeSelect Event). I also want to stop the TreeView from highlighting the top level nodes if the user selects them i.e. stop the TreeView from changing the background ...