Dealing with WinForms Combobox and name/value items.#

I just read this article on aspalliance.com by Sandeep Archarya.

I think the article had 2 main points.  One was that databinding a combobox is not "bug free" because the act of manually databinding to a combobox causes the SelectedIndexChanged event to fire.  The second point was to show how to create a simple namevalue class to be added to the combobox items collection to get around the "problem" of combobox's taking an object as the item in it's list (as opposed to a name value pair).

I would point out the following:

First, I am not sure that I would call the SelectedIndexChanged event firing a bug.  When you manually databind a list, the first item become selected by default, and thus the selectedindex HAS changed, from -1 to 0.

Second, if you consider this a problem you can get around it a couple different ways.

1) Don't use manual databinding.

In the designer, select a datasource or create a new one.  I created a simple employee object and created an object datasource for this employee.  This creates a EmployeeBindingSource object that I bind my employee list to.  Using this method, I didn't experience the SelectedIndexChanged event firing on the databind.

Private list As New System.Collections.Generic.List(Of employee)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    '*** create some fake employee objects
   For i As Integer = 70 To 80
      list.Add(New employee(i, Chr(i)))
   Next

    '*** this will populate our control (Combobox1)
   Me.EmployeeBindingSource.DataSource = list

End Sub

2) You can use manual databinding, and manually detach and attach the event handler for this event.

Private list As New System.Collections.Generic.List(Of employee)

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
    '*** create some fake employee objects
   For i As Integer = 70 To 80
      list.Add(New employee(i, Chr(i)))
   Next

    '*** remove the handler
    RemoveHandler ComboBox1.SelectedIndexChanged, AddressOf ComboBox1_SelectedIndexChanged
    '*** databind
    Me.ComboBox1.ValueMember = "id"
    Me.ComboBox1.DisplayMember = "name"
    Me.ComboBox1.DataSource = list
    '*** add the handler back
    AddHandler ComboBox1.SelectedIndexChanged, AddressOf ComboBox1_SelectedIndexChanged
End Sub

 

Categories: .Net | .Net Framework | DataBinding | WinForms
Friday, November 10, 2006 4:32:43 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

.Net 3.0 Free Online Labs From Microsoft#

Microsoft is offering some free online lab training on .Net 3.0 for a limited time.

Use this link: http://msdn.microsoft.com/virtuallabs/netframe/default.aspx

Categories: Programming | .Net
Monday, November 06, 2006 4:37:39 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

VS.Net for Database Launch Event#

Microsoft is releasing "Visual Studio Team Edition 2005 for Database Professionals" (who on Earth comes up with these names????).

MS is holding some launch events all over where you can come (for free) and learn a little about this product, which from what I saw looks pretty slick.

http://www.teams-deliver.com

Categories: .Net | VS.Net | SQL Server
Monday, November 06, 2006 4:36:25 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Red Gate SQL Refactor Tool Looks Cool#

Red Gate has a pretty interesting tool called SQL Refactor:

http://www.red-gate.com/products/sql_refactor/index.htm

 

The "Layout Code" feature looks awesome.  It basically takes a terrible looking select statement and turns it into a nicely formatted block.

 

Here is a code project article that shows some of these features:

http://www.codeproject.com/showcase/SQLRefactor.asp

 

Categories: SQL Server
Monday, November 06, 2006 4:34:42 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Convert RTF to HTML#

More than once I have looked into a way to convert RTF into HTML.  Mostly because there are RTF textboxes available for winforms, but you might want to save the page as HTML, and not RTF.

This article shows a way to do this that:

http://www.codeproject.com/vb/net/RTFToHTML.asp

Categories: Programming | .Net | .Net Framework
Monday, November 06, 2006 4:33:56 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Missing Step in, Step Out and Macros in VS.Net#

A while back I had some problems with a coworkers VS.net settings.

They were missing the step in and step out as well as the Macros option in the tools menu.

We were able to get these back by changing the VS.Net settings by going to Tools->Import and Export settings.

Then select to Import settings and pick where you want to backup your current settings.

Then I think we picked "Visual Basic Development Settings" or maybe "General Development Settings."  This seemed to get things back to normal for the most part.

I still have a few problems, like if I am working on some file, that file will not be highlighted in the solution explorer (what a pain) and I can't right click on a webform and select "View Code" (what a pain).

It looks like MS was trying to make it really customizable, but I think they ended up making it a pain to get things working the way you expect them to.

 

UPDATE:
I was able to quickly find a setting to make sure that the current page I was working on became tracked in Solution Explorer:

 

Categories: Programming | .Net | VS.Net
Wednesday, November 01, 2006 4:38:40 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Custom Credentials for SQL Server Reporting Services 2005 Web ReportViewer#

SQL Server Reporting Services 2005 allows you to connect with a web based ReportViewer control.

This control needs to provide credentials for the reporting server to authenticate the user requesting the report.  By default, the account running the asp.net worker process is used, but you can use the code in this forum posting to create you own custom credentials.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=409854&SiteID=1

 

Categories: Programming | SQL Server | Reporting
Tuesday, October 24, 2006 3:34:26 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Anti-Spam GreyListing#

I recently started getting some soft bounces coming back from Yahoo. 

I believe that this is a "greylisting" operation on their part:  "Message delivery has been delayed."

The typical "lists" are Blacklists (all email is rejected) and Whitelists (all email is accepted).

Greylists utilize what is called a soft error, or soft bounce on the email server. 

When sending an email, there are some errors that cause the transmission to fail and halt, and there are others that indicate that the sender should "try again later."

For example, if you try to send an email to an account that doesn't exist, the sending server will not try to deliver the message again.  But if the error is something like "Mailbox is full", then the sender will keep trying N number of times.

Almost all spammers will not bother to resend these soft bounces.  They are kicking of millions of emails, it isn't worth their time to deal with these soft bounces.

So greylisting does the soft bounce, and sees if the sender tries again.  If they do, then yahoo labels them as an OK sender, and allows their email through.  If they don't try again, yahoo can label them a spammer, and block them out.

 

Categories: Networking | Email
Tuesday, October 24, 2006 3:31:48 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

AJAX Toolkit Library Growing#

A while back I was looking at the AJAX toolkit page (http://ajax.asp.net/ajaxtookit) and I was really not impressed with anything I saw.

Things like the "Confirm" button, which is basically a button with 10 seconds of javascript coding built into it isn't a big deal, IMO.

But their list of controls has really grown and there are some really interesting things in that toolkit.

It still boggles my mind that they don't have an autocomplete dropdown list where your selections are LIMITED to the choices from the list.

 

Categories: Programming | .Net | AJAX | Javascript
Tuesday, October 24, 2006 3:29:30 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

ReportViewer with heigh=100%#

When you try to assign the web reportviewer control to a height of 100%, it displays as a very short (height wise) format.  For me, adding the style attributes to the form did the trick.

The solution to this problem was found on this page: http://msdn2.microsoft.com/en-us/library/ms252090.aspx.

Considerations for XHTML and ReportViewer Web Server Control

If you configure the ReportViewer Web server control to run in asynchronous mode in an application that is written in XHTML, you must follow specific steps to display the ReportViewer control properly. If the ReportViewer control uses relative height (for example, if the height is specified as a percentage of available space), the control collapses to a height of 0 pixels as a result of how frames and DIV tags render in containing tables in XHTML. You can avoid this problem by using one of the following workarounds:

  • Explicitly set the height on the on the ReportViewer control to an actual value rather than a percentage.

  • Add the following style setting to the head tag:

    <style>html,body,form {height:100%}</style>.

    By forcing the html, body and form tags to maximum height, the frame used in the ReportViewer control will also grow to maximum height, making it visible on the page.

  • Remove the xhtml doctype from the page.

Categories: Programming | Database | SQL Server | Reporting
Tuesday, October 24, 2006 3:27:04 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Open letter to John Madden... very funny.#
This article is a (fake, but funny) letter from the lowest ranked player in Madden 2k7 to John Madden.

http://www.thephatphree.com/features.asp?StoryID=3159&SectionID=2&LayoutType=1/

Very funny stuff.

Categories: Funny Stuff
Friday, October 20, 2006 3:36:13 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Using ObjectSwap To Avoid Flash/IE Activation Problems#

Recently Microsoft lost a lawsuit which required that they not "automatically" enable dynamic content in their browser, or something.

Whatever.  The result is that you now have to CLICK on flash swf files running in your browser before they will be "Activated".

The way to get around this is to use javascript to do the dirty work. 

Check out this link for a quick include that can help with the work around:

http://www.sitepoint.com/article/activex-activation-issue-ie

 

Categories: Programming | Flash | Javascript
Thursday, October 12, 2006 3:41:01 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Printing Vb.Net Forms with PrintForm Component#

Microsoft has released their first 3 Power Packs for Visual Basic 2005, which are "free Add-Ins, Controls, Components, and Tools for you to use with Visual Basic 2005 to make developing great applications even easier."

1 of the first 3 is the Microsoft PrintForm Component 1.0 , which gives you the ability to easily print a form.

I could have really used this on my last project, where I manually wrote the code to do just that.

Categories: Programming | .Net | VB.Net | VS.Net
Monday, October 09, 2006 2:58:15 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Make Use Of Culture in SQL Reporting Services Local Reports#

When using SQL Reporting services, you can format things such as dates and currency.

However, depending on the situation you might want to:

  1. Show a report with culture X on a computer running culture Y.
  2. Show a report using the same culture settings as the local computer.

To do (1), all you have to do is set the "Language" parameter of the local report in design time.

To get (2) to work, you need to set the Language parameter of the report as the expression "=User.Language".  This will set the report culture as the culture that the hosting program is running under.

If you have a program that you need to switch between different cultures, you can do so with the following line of code (which changes the culture to "English-Ireland")

System.Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-IE", False)

More information can be found at: http://msdn2.microsoft.com/en-us/library/ms156493.aspx

Categories: Programming | .Net | .Net Framework | Reporting
Monday, October 09, 2006 1:43:24 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Convert a String to a Byte Array in VB.Net#

I had a snippet on my site for converting a byte array to a string, but I didn't have anything for going the other way.

This function should do the trick.

Public Shared Function StringByByteArray(ByVal s As String) As Byte()
    Return System.Text.Encoding.UTF8.GetBytes(s)
End Function


Categories: Programming | .Net | VB.Net
Wednesday, October 04, 2006 3:44:23 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Regular Expressions Tutorial#

This is really a great tutorial on using regular expressions.

http://www.regular-expressions.info/tutorial.html

The information is broken down into sections, which appear on the left hand side.

 

Categories: Programming | .Net
Tuesday, October 03, 2006 3:50:20 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Upload Multiple Files w/ Progress Bar Using Flash#

This is a pretty neat example of using Flash and ASP.NET, 2 technologies that I have expreience with.

http://www.codeproject.com/aspnet/FlashUpload.asp

I will need to try this in one of my projects.

Categories: Programming | Flash
Tuesday, October 03, 2006 3:48:56 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Getting the Access Default Menu Back#

I know Access is old news, but I have recently been asked to take a look at an old Access app.

This application replaces the existing menu at the top with a custom one, which really limits what you can do.

The solution to getting the menu back is to right click in the menu area, select customize, highlight "Menu Bar" and select properties, and change "Allow hide/show..." checkbox.  After you do this, you can then add it back into your form.

Categories: Programming | Database
Tuesday, October 03, 2006 3:47:04 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Default Buttons in ASP.NET 2.0#

ASP.NET has this thing where pressing Enter on a page will cause it to be submitted, but no submit action is taken, mostly because you can have multiple buttons on a page, and it isn't sure which button it should consider clicked when you press enter.

The solution to this was the "__EVENTTYPE" field.  Click here for more info on __EVENTTYPE.

Thankfully ASP.NET 2.0 has introduced some new features to help remove this complexity.

Scott Gu blogs about the new form defaultButton property, as well as the new SetFocusOnError property of the validators here:

http://weblogs.asp.net/scottgu/archive/2005/08/04/421647.aspx

 

Categories: Programming | .Net | ASP.Net
Saturday, September 30, 2006 3:55:52 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Solution to dasBlog "Remember My Login" Not Working#

A while ago, maybe 3 months, my blog stopped remembering my login.  When I login I can click to have it remember my login, and thus when I return to the site I don't have to login every time.

Well I finally arrived at the problem. 

In IIS settings for the website, under the ASP.NET tab, if you click the "Edit Configuration" button, and then the authentication tab, you have the option to set the expiration length for the cookie, which was set to 1 hour.

I changed it to a larger value, restarted the IIS processes, and it appears to be working great now!

Categories: Blogging | Programming | ASP.Net | dasBlog | IIS
Friday, September 29, 2006 5:00:30 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

All content © 2010, Christopher May, Inc
Open Job Positions
On this page
Google Ads
This site
Calendar
<November 2006>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
Archives
Sitemap
Blogroll OPML
Disclaimer

Powered by: newtelligence dasBlog 2.3.9074.18820

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts


Pick a theme: