winforms

Delete DataGridView line

How can I delete a line form a binded DataGridView when pressing Delete key? ...

DataGridViewComboBoxColumn adding different items to each row . .

I am building a table using the DataGridView where a user can select items from a dropdown in each cell. To simplify the problem, lets say i have 1 column. I am using the DataGridViewComboBoxColumn in the designer. I am trying to support having each row in that column have a different list of items to choose from. Is this possible? ...

Background color of a ListBox item (winforms)

How can I set the background color of a specific item in a System.Windows.Forms.ListBox? I would like to be able to set multiple ones if possible. ...

Programmatically setting the record pointer in a C# DataGridView

How do I programmatically set the record pointer in a C# DataGridView? I've tried "DataGridView.Rows[DesiredRowIndex].Selected=true;", and that does not work. All it does is highlight that row within the grid; it doesn not move the record pointer to that row. ...

Set selected item on a DataGridViewComboboxColumn

I have a datagridview with a DataGridViewComboboxColumn column with 3 values: "Small", "Medium", "Large" I get back the users default which in this case is "Medium" I want to show a dropdown cell in the datagridview but default the value to "Medium". i would do this in a regular combobox by doing selected index or just stting the Te...

How do I enable/disable Cut/Copy/Paste menu and toolbar items in a generic way?

I have a windows forms application with controls like textbox, combobox, datagridview etc. These controls allow a user to use the clipboad, i.e. cut/copy and paste text. It is also possible to delete text (which is not related to the clipboard). My application has a menubar with an Edit item containing Cut/Copy/Paste/Delete items, and a...

Save and Restore Form Position and Size

In a WinForms 2.0 C# application, what is the typical method used for saving and restoring form position and size in an application? Related, is it possible to add new User scoped application settings AT RUNTIME? I totally see how to add settings at design time, that's not a problem. But what if I want to create one at runtime? More de...

Easy way to set CurrentCulture for the entire application?

In a .net 2 winforms application, what's a good way to set the culture for the entire application? Setting CurrentThread.CurrentCulture for every new thread is repetitive and error-prone. Ideally I'd like to set it when the app starts and forget about it. ...

DateTimePicker: pick both date and time

Is it possible to use DateTimePicker (Winforms) to pick both date and time (in the dropdown)? How do you change the custom display of the picked value? Also, is it possible to enable the user to type the date/time manually? ...

Baseline snaplines in custom Winforms controls

I have a custom user control with a textbox on it and I'd like to expose the baseline (of the text in the textbox) snapline outside of the custom control. I know that you create a designer (inherited from ControlDesigner) and override SnapLines to get access to the snaplines, but I'm wondering how to get the text baseline of a control t...

Windows Form with Resizing Frame and no Title Bar?

How can I hide the title bar from a Windows Form but still have a Resizing Frame? ...

WinForm - draw resizing frame using a single-pixel border

In a Windows Form with a Resizing Frame, the frame border draws with a raised 3-D look. I'd like it to draw with a flat single pixel border in a color of my choosing. Is this possible without having to owner draw the whole form? ...

How can I build C# ImageList Images from smaller component images?

I'd like to make status icons for a C# WinForms TreeList control. The statuses are combinations of other statuses (eg. a user node might be inactive or banned or inactive and banned), and the status icon is comprised of non-overlapping, smaller glyphs. I'd really like to avoid having to hand-generate all the possibly permutations of ...

How do you limit height of a Sytem.Windows.Form to an exact value?

What I am trying to achieve is a form that has a button on it that causes the Form to 'drop-down' and become larger, displaying more information. My current attempt is this: private void btnExpand_Click(object sender, EventArgs e) { if (btnExpand.Text == ">") { btnExpand.Text = "<"; _expanded = true; this...

How can I get the current exception in a WinForms TraceListener

I am modifying an existing WinForms app which is setup with a custom TraceListener which logs any unhandled errors that occur in the app. It seems to me like the TraceListener gets the message part of the exception (which is what gets logged), but not the other exception information. I would like to be able to get at the exception objec...

Automatically select all text on focus in WinForms TextBox

When a C# WinForms text box receives focus, I want to select all the text in the textbox. To see what I mean, click in your web browser's address bar. See how all text was selected? I want to do that. FASTEST GUN ALERT: please read the following before answering! Thanks guys. :-) Calling .SelectAll() during the .Enter or .GotFocu...

Is there a control for a .Net WinForm app that will display HTML

I have a .net (3.5) WinForms application and want to display some html on one of the forms. Is there a control that I can use for this? ...

Setting the focus in a datagridview in windows form

I have a datagridview that accepts a list(of myObject) as a datasource. I want to add a new row to the datagrid to add to the database. I get this done by getting the list... adding a blank myObject to the list and then reseting the datasource. I now want to set the focus to the second cell in the new row. To CLARIFY i am trying to set ...

Firing UI control events from a Unit Test

As a beginner to TDD I am trying to write a test that assumes a property has had its value changed on a PropertyGrid (C#, WinForms, .NET 3.5). Changing a property on an object in a property grid does not fire the event (fair enough, as it's a UI raised event, so I can see why changing the owned object may be invisible to it). I also ha...

Why do all Winforms programs require the [STAThread] attribute?

Why do Winforms programs have the [STAThread] attribute on the Main() method and what are the consequences of removing it? ...