January 22nd, 2008 Luke
If you’ve done any work with ComboBoxen lately, you might have noticed that, even if you used my method for storing text/values into a combobox, you still can’t seem to use myComboBox.SelectedText to actually retrieve the SelectedText of the Combobox.
Why is this? I don’t know.
But I do know that if you change your call slightly, you can do it - you just refer to ComboBox.Text, instead of ComboBox.SelectedText:
string myText = ComboBox.Text;
It doesn’t quite make sense to me, but that’s how you work around the issue.
Posted in clientapp, csharp | 1 Comment »
January 21st, 2008 Luke
Right now I’m working on a project that involves generating reports, based on a variety of user-selected criteria.
In order to make it easier for the user to choose what they want reports on(and also make it harder to screw up), we’ve decided to use the ComboBox component for all of our data - so that they can only select that values that are actually viable to report on.
The ComboBox is a little weird, however, because unlike the website-based DropDownList element, it doesn’t contain any ListItems. You can access ComboBox.SelectedValue, or ComboBox.SelectedText, but there didn’t seem to be any way to actually store values and text into a combo box.
As it turns out, it’s easier than you’d think. You can store your data into a datatable, and then give the ComboBox the names of the columns you want to use for values and for text:
DataTable dt = new DataTable();
dt.Load(myQuery.GetReader());
cbPictures.DisplayMember = "column_1";
cbPictures.ValueMember = "column_2";
cbPictures.DataSource = dt;
And with that finished, you will now have all the values of column_1 for your text, and all the values of column_2 for your data.
Posted in clientapp, csharp | No Comments »
January 18th, 2008 Luke
Have you ever been plugging away at a client app, and suddenly found yourself in need of a way to change the startup form for the project?
I have. And the only answers I could find while Googling for the issue were “Go to project properties->application->’Startup Object’, and select your form from there”. Except that, whenever I tried to do that, the only thing that shows up under ‘Startup Object’ was my client app - myApp.program.
As it turns out, there is a way to change the startup form - you need to edit Program.cs(I would assume that under VB you need to change Program.vb). This is what the code looks like:
namespace MyProgram
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new myForm());
}
}
}
As it turns out, all you need to change is the line that says Application.Run(new myForm()); - just change the word after the new constructor to the name of the class/form you want to set as your startup form. Handy!
Posted in clientapp, csharp | No Comments »
January 4th, 2008 Luke
I’m working on a project right now that involves generating PDF reports from a C# client app.
One thing that we thought would be cool is if, after generating the PDF, it was automatically opened in whatever PDF reader the user had on their computer - and as it turns out, there is a simple one-liner that opens the file using whatever application is associated with it on the host machine:
System.Diagnostics.Process.Start(fileName);
Whether you’re passing a PDF, HTML file, or anything else, that call will open it up in the program that the host computer has associated with it.
Posted in PDF, clientapp, csharp, generic, snippet | No Comments »