winforms

Howto determine order of displayed columns in a datagridview binded to a datasource

Is there a way to determine the order of the columns displayed in a datagridview when binding it to a datasource whitch contains an underlying IList ? I thought there was a specific property attribute for this purpose but can't recall what it actually was. eg: public void BindToGrid(IList<CustomClass> list) { _bi...

Can BeginInvoke interrupt code already running on the UI thread?

Suppose I have some code which is running in the UI thread, which spawns a new thread to do work in the background, and then goes on to do UI work. When the background work is done, BeginInvoke is called from the new thread. If the UI work is still going on, will the callback given to BeginInvoke interrupt the UI work, or will it wait?...

C# Panel autoscroll doesn't work

I have a panel with a picturebox on it. When the content of the picturebox is too large I want scrollbars. I've set the autoscroll set to true on the panel. But when the content of the picturebox is larger then the height of the panel/picturebox no scrollbars are shown. My panel is anchored top, left, bottom, right. The picturebox is al...

How do I design View logic into c# projects

I have three c# projects in my solution. One is a console app that simply calls into a class library project. The class library project does all the processing for the application. Then there is a WinForm project that displays a form and then when a button is pressed, calls the same logic in the class library project. As a result, th...

C# WebBrowser stops focus on richtextbox

Hi, I have problem with WebBrowser component. For some reason, when I click into it, it disables me from setting focus on richTextBox. I have 2 almost the same forms. Main difference between first and second form is, that form1 is modifying WebBrowser DocumentText and form2 is using webBrowser to display content of temporary file. F...

Getting records from between Date X and Date Y from my Access database?

I have a table called Recharge in a Access Database. Some of the fields are RechargeDate, Account, Number, etc. I wanted to retrieve all records between two dates so I wrote the following query: string Query = "select * from Recharge where Account='" + comboBox1.Text + "' and RechargeDate between '"+dateTimePicker1.Value.Date.ToShort...

Why Browsable attribute makes property not bindable?

Hi, I'm trying to use System.Windows.Forms.PropertyGrid. To make a property not visible in this grid one should use BrowsableAttribute set to false. But adding this attribute makes the property not bindable. Example: Create a new Windows Forms project, and drop a TextBox and PropertyGrid onto Form1. Using the code below, the width of...

Visual Studio 2008 Winform designer fails to load Form which inherits from generic class.

Hi, i have a winforms project, and i created a class on assembly A that inherits from System.Windows.Forms.Form to serve as a base class for various forms on my project, the base class is something like: public partial class DataForm<T> : Form where T : class { T currentRecord; protected T CurrentRecord { get ...

cast existing Button to IPy subclass

I have a test harness that runs in an embedded IronPython engine in our C# app. Some of the tests are UI automation that simulate button clicks, etc. # assume code to find an existing button, 'b' is an instance of System.Windows.Forms.Button b.OnClick(EventArgs()) The issue I have is that the above code works on IPy 2.0.2 and not o...

TabIndex problem. Only getting a system beep.

Background: I've got a WinForm application with a ComboBox and a TabControl with two pages. On page one of the TabControl, I've got a FlowLayoutPanel containing about 10 Panels. Each of those Panels contain a Label and a TextBox. I'm using Visual Studio 2008 as my IDE. Problem: I'm not able to tab between any of my controls. I go to Vie...

Trouble with TreeView.DrawNode - OwnerDrawText

I have an app that is connected to a remote server and polling data when needed. It has a TreeView where the Nodes represent the objects that are available and the color of the text indicate whether the data has been loaded or not; gray-italicized indicates not loaded, black, regular text is loaded. Currently I have set the TreeView to...

Is there any sense in worrying about SQL injection in a Winforms project?

In SO and elsewhere it's nearly impossible to post long concatenated SQL instructions in sample code without someone politely pointing out that it's better to use parameterized input and stored procedures. Recent example here. But is it meaningful to worry about SQL injection in a Winforms project? ...

static class variable scope issue in C# winforms - why doesn't this bit of code work?

Hi, I've got two different forms in my WinForms app (MainForm and Form2 say). They both ask for an access of MyDataSet, via a "getInstance" static method. The issue is after MainForm has got an instance, when Form2 needs to get an instance the static "myDataSet" variable is null, whereas I expect to have been already set? Any ideas? ...

WPF vs Windows Forms in desktop applications

Hi, I've been developing C# Windows Forms applications for a couple of years and while I've heard and read about WPF I've never really come in close contact to it. With some time to spare this spring I though I'd give it a go though, but first it'd be intresting to know what you guys thought about it. What do you think, is it worth the ...

Drag, Drop and Delete

Hi All I have a question about drag and drop in WinForms. I know how to enable the user to drag and drop controls around inside the form, but what I'm now trying to do is enable them to drag a LinkLabel ontop of a"Recycle Bin" icon inside my Form and when it detects that something has been dropped onto the Recycle Bin icon, that control...

In TableLayoutPanel if Dock = Fill and AutoSize = true then last column/row occupy all remaining space.

Hi all, In TableLayoutPanel if we set AutoSize = true and Dock = fill then last column/row will occupy all remaining space. How to set it to required height (row) and width (column)? ...

C# listview - embedding controls

Hi , Can anybody help me with embedding controls in the listview. I need to add button controls as subitem of listview. thanks ...

Using IDisposable To Unsubscribe an Event-- Do I need to Put Other Things Inside the Dispose?

I have the following class public class Presenter: IDisposable { public IView View {get;private set;} //snip other object reference, all managed public Presenter(IView view) { View=view; View.MouseUp += MouseUpEvent; } public void MouseUpEvent() { //do whatever you want to do on mouse up } public...

Connecting to sql server database mdf file without installing sql server on client machine ?

I am creating a window application that need to use sql server database. I want to install this application to client machine without installing sql server so that my application can still connect to a database i.e mdf file that i will be providing at client system. How can i connect to a database(mdf) on client machine through my win...

[WindowsForms] Graphics transparency on PictureBox

First of all, this is not about making the PictureBox control transparent. It's about bitmap transparency on the fully opaque "canvas". The PictureBox will always have the size of 300*300 with white background. No transparency is needed for the control. What I need is the way to draw the transparent rectangle (or whatever else) onto th...