.Finalize() – Summer Travel, Blueberries, and Data Binding

.Finalize() – Summer Travel, Blueberries, and Data Binding

nother summer, another Tech?Ed. This is, of course, the 10th anniversary of Microsoft’s annual geekfest, and I’ve had the honor of being at all of them besides one somewhere in the middle of the run. I managed to grab a speaking gig at Tech?Ed in both Dallas and Barcelona this year, and these trips clogged up a travel schedule that was already too full for the summer. Let’s review how the speaking and travel have gone since we last spoke. There was the week in Dallas, for Tech?Ed. How much beef can one person consume in one week? I went vegetarian for the remainder of the summer, for the most part.

While I was at a conference in Las Vegas, I bet three quarters and a nickel and won $10.00?living on the edge! I spent two days in Redmond, then four in New York. I enjoyed four Broadway plays in three days. Another two days in Redmond, then four days in Barcelona. If you haven’t been to Barcelona, go. It’s an amazingly beautiful city with friendly people, great food, an easy transit system, and fascinating architecture. Just don’t go in August (luckily, we didn’t). It’s hot. Apparently, it’s currently 106?F as I write this in mid-August. I’ll skip that. In July, it was crisp, warm, and a pleasure. Oh, and the conference was fun, too. They really know how to throw a party at Tech?Ed Europe.

Then there was the college roommate reunion over July 4th weekend in Monterey, followed by a week spent recording more training content for AppDev in Minneapolis. My friend, ex-manager, current speaker coordinator at various conferences, editor for this publication, and biking buddy Erik Ruthruff spent the afternoon with me on a beautiful spin around a few lakes in Minneapolis. It’s amazing that there’s an apparent inverse relationship between the number of days the public can actually spend cycling with the number of miles of usable bike trails to be had in said municipality. Minneapolis has many miles of trails, yet only around 10 days per year that aren’t cold. Los Angeles has 360 days per year of perfect riding weather, and perhaps 10 miles of usable trails (the remainder are in gang territory?only the brave and the very fast ride there). Anyway, we biked 17.4 miles. He did fine. My legs barely worked for a few days.

In Minneapolis, I had the fortune of being in town for the yearly Aquatennial Celebration (a yearly festival devoted to?I’m not kidding?water sports, which one local justified in that there’s so little time in the year to enjoy the outdoors, they have to find made-up excuses to celebrate, but I’m sure there’s a better explanation than that; maybe it has something to do with the statement on the license plates: 10,000 Lakes). In Minneapolis, I had the misfortune of staying at a hotel that was one of many hotels hosting some youth soccer tournament, bringing in pre-teens and their families from around the country. I found that the amount of noise a hotel full of 12-year-olds can make far outweighs the capacity of a good set of earplugs. I fully expected to see the kids staying upstairs from me turn out to be the size of small Mack trucks. I only have the one good ear?it makes sleeping in noisy hotels easier?but it was still an experience I wouldn’t wish on anyone. If you were there with your kids at that time, shame on you. There is no excuse for that kind of behavior. Gosh, I feel like the grumpy old neighbor from next door when you were a kid.

One more trip to New York, and then my final trip of this summer marathon?to Houston to visit my family for EatFest 2003 (that’s not an official event, we just tend to eat out a lot when I’m in town, and there’s a lot of good food to be had in Houston) in the sweltering “it’s only 102 out but it feels like 112” heat. Finally, I’m back in lovely Los Angeles.

My favorite part of summer (besides the fact that summer isn’t usually hot here?its September and October that will get you) is the fruit at CostCo. You have a CostCo where you are, right? This is one of my criterion for finding a place to “settle” (you don’t settle in Los Angeles, you generally pass through) when I grow up?I need to be within an hour of CostCo. Among the palettes of lawn-care products, batteries, film, and life-time supplies of canned tuna, they sell the most amazing fruits and vegetables there, and I eat a lot of peaches and blueberries in the summer. Maybe the rogue strawberry, as well. CostCo packages their fruit in mass quantities, and I just go for it. My friend, business partner, and co-author Andy Baron and I were shopping at CostCo once, and we decided to split a case of blueberries. We were discussing the recommended serving size for a portion of blueberries, and Andy hit the nail on the head when he suggested that the correct service size is “the container they’re in.” Andy’s full of similar deep thoughts. On the other hand, I can’t help thinking of Willy Wonka, with the little girl who ate the forbidden gum and turned blue and berry-shaped. I’m on my way. Of course, blueberries are both good and good for you. Everyone tells me they’re excellent anti-oxidants. I’m not sure what oxidants are or why I should be against them, but I’m glad blueberries take care of them for me.

Speaking of Andy, he recently solved an apparent .NET programming mystery for me, and I wanted to share his solution. Let me provide a little setup: I wanted to provide a simple Windows-based data entry form in which users could enter their phone numbers, selecting from various types of phone numbers (Home, Mobile, Work, and so on). I created an array containing the phone types, and bound four ComboBox controls to the array. That is, the form contained the following code (simplified for display here):

   private String[] PhoneTypes =      new String[] {"Home", "Mobile", "Work"};   private void Form1_Load(object sender,    System.EventArgs e)   {     comboBox1.DataSource = PhoneTypes;     comboBox2.DataSource = PhoneTypes;     comboBox3.DataSource = PhoneTypes;   }

I load the form, select a phone type from one of the combo boxes, and the result is certainly not what I intended. Try it yourself?it will just take a minute. I’ll wait.

As you saw, selecting a phone type from one of the combo boxes selects the same phone type in all the combo boxes. You may wonder what’s going on. At first I thought that one solution would be to create three copies of the PhoneTypes array. I could assign each copy of the array as the data source of one of the combo boxes, but that would be an inefficient way to go about it. The problem is that when you bind controls to data sources on a Windows form, as I’ve done here, the form creates a single BindingContext object to manage the data binding, and adds a single object that inherits from the BindingManagerBase class (here, a CurrencyManager object) for each data source. Because there’s only a single BindingContext, and only a single CurrencyManager object, there’s only a single current row within the data source, and each combo box always displays the same value.

Andy came to the rescue here with what turns out to be a perfectly obvious solution, once you know it. That is, you aren’t required to use the form’s single BindingContext for all your data binding. You can create your own BindingContext object, which will then manage individual CurrencyManagers for each instance. In other words, rewriting the code so that it looks like this solves the problem:

   private String[] PhoneTypes =      new String[] {"Home", "Mobile", "Work"};   private void Form1_Load(object sender,      System.EventArgs e)   {     // Use the form's default BindingContext.     comboBox1.DataSource = PhoneTypes;     comboBox2.BindingContext = new BindingContext();     comboBox2.DataSource = PhoneTypes;     comboBox3.BindingContext = new BindingContext();     comboBox3.DataSource = PhoneTypes;   }

ComboBox1 can use the form’s default BindingContext, but the other two controls need to set up their own individual contexts for binding (supplied by their individual BindingContext objects). That’s all it takes to solve this problem?that is, adding two lines of code, creating a unique BindingContext object for all but the first ComboBox control, made it possible to use a single data source for multiple controls.

The workings of the BindingContext and CurrencyManager objects can seem confusing at first, but once you understand how they’re working under the covers to provide data binding for Windows forms, you’ll be amazed at the elegance and the simplicity of the design. And thanks to Andy for the correspondingly elegant and simple solution to my little problem. And speaking of elegant and simple: I’m heading out for more blueberries. The season’s just about over, and once they’re gone, they’re gone until next summer.

devx-admin

devx-admin

Share the Post:

The Role Of AI Within A Web Design Agency?

In the digital age, the role of Artificial Intelligence (AI) in web design is rapidly evolving, transitioning from a futuristic concept to practical tools used

5G Innovations

GPU-Accelerated 5G in Japan

NTT DOCOMO, a global telecommunications giant, is set to break new ground in the industry as it prepares to launch a GPU-accelerated 5G network in

AI Ethics

AI Journalism: Balancing Integrity and Innovation

An op-ed, produced using Microsoft’s Bing Chat AI software, recently appeared in the St. Louis Post-Dispatch, discussing the potential concerns surrounding the employment of artificial

Savings Extravaganza

Big Deal Days Extravaganza

The highly awaited Big Deal Days event for October 2023 is nearly here, scheduled for the 10th and 11th. Similar to the previous year, this

The Role Of AI Within A Web Design Agency?

In the digital age, the role of Artificial Intelligence (AI) in web design is rapidly evolving, transitioning from a futuristic concept to practical tools used in design, coding, content writing

5G Innovations

GPU-Accelerated 5G in Japan

NTT DOCOMO, a global telecommunications giant, is set to break new ground in the industry as it prepares to launch a GPU-accelerated 5G network in Japan. This innovative approach will

AI Ethics

AI Journalism: Balancing Integrity and Innovation

An op-ed, produced using Microsoft’s Bing Chat AI software, recently appeared in the St. Louis Post-Dispatch, discussing the potential concerns surrounding the employment of artificial intelligence (AI) in journalism. These

Savings Extravaganza

Big Deal Days Extravaganza

The highly awaited Big Deal Days event for October 2023 is nearly here, scheduled for the 10th and 11th. Similar to the previous year, this autumn sale has already created

Cisco Splunk Deal

Cisco Splunk Deal Sparks Tech Acquisition Frenzy

Cisco’s recent massive purchase of Splunk, an AI-powered cybersecurity firm, for $28 billion signals a potential boost in tech deals after a year of subdued mergers and acquisitions in the

Iran Drone Expansion

Iran’s Jet-Propelled Drone Reshapes Power Balance

Iran has recently unveiled a jet-propelled variant of its Shahed series drone, marking a significant advancement in the nation’s drone technology. The new drone is poised to reshape the regional

Solar Geoengineering

Did the Overshoot Commission Shoot Down Geoengineering?

The Overshoot Commission has recently released a comprehensive report that discusses the controversial topic of Solar Geoengineering, also known as Solar Radiation Modification (SRM). The Commission’s primary objective is to

Remote Learning

Revolutionizing Remote Learning for Success

School districts are preparing to reveal a substantial technological upgrade designed to significantly improve remote learning experiences for both educators and students amid the ongoing pandemic. This major investment, which

Revolutionary SABERS Transforming

SABERS Batteries Transforming Industries

Scientists John Connell and Yi Lin from NASA’s Solid-state Architecture Batteries for Enhanced Rechargeability and Safety (SABERS) project are working on experimental solid-state battery packs that could dramatically change the

Build a Website

How Much Does It Cost to Build a Website?

Are you wondering how much it costs to build a website? The approximated cost is based on several factors, including which add-ons and platforms you choose. For example, a self-hosted

Battery Investments

Battery Startups Attract Billion-Dollar Investments

In recent times, battery startups have experienced a significant boost in investments, with three businesses obtaining over $1 billion in funding within the last month. French company Verkor amassed $2.1

Copilot Revolution

Microsoft Copilot: A Suit of AI Features

Microsoft’s latest offering, Microsoft Copilot, aims to revolutionize the way we interact with technology. By integrating various AI capabilities, this all-in-one tool provides users with an improved experience that not

AI Girlfriend Craze

AI Girlfriend Craze Threatens Relationships

The surge in virtual AI girlfriends’ popularity is playing a role in the escalating issue of loneliness among young males, and this could have serious repercussions for America’s future. A

AIOps Innovations

Senser is Changing AIOps

Senser, an AIOps platform based in Tel Aviv, has introduced its groundbreaking AI-powered observability solution to support developers and operations teams in promptly pinpointing the root causes of service disruptions

Bebop Charging Stations

Check Out The New Bebob Battery Charging Stations

Bebob has introduced new 4- and 8-channel battery charging stations primarily aimed at rental companies, providing a convenient solution for clients with a large quantity of batteries. These wall-mountable and

Malyasian Networks

Malaysia’s Dual 5G Network Growth

On Wednesday, Malaysia’s Prime Minister Anwar Ibrahim announced the country’s plan to implement a dual 5G network strategy. This move is designed to achieve a more equitable incorporation of both

Advanced Drones Race

Pentagon’s Bold Race for Advanced Drones

The Pentagon has recently unveiled its ambitious strategy to acquire thousands of sophisticated drones within the next two years. This decision comes in response to Russia’s rapid utilization of airborne

Important Updates

You Need to See the New Microsoft Updates

Microsoft has recently announced a series of new features and updates across their applications, including Outlook, Microsoft Teams, and SharePoint. These new developments are centered around improving user experience, streamlining

Price Wars

Inside Hyundai and Kia’s Price Wars

South Korean automakers Hyundai and Kia are cutting the prices on a number of their electric vehicles (EVs) in response to growing price competition within the South Korean market. Many

Solar Frenzy Surprises

Solar Subsidy in Germany Causes Frenzy

In a shocking turn of events, the German national KfW bank was forced to discontinue its home solar power subsidy program for charging electric vehicles (EVs) after just one day,

Electric Spare

Electric Cars Ditch Spare Tires for Efficiency

Ira Newlander from West Los Angeles is thinking about trading in his old Ford Explorer for a contemporary hybrid or electric vehicle. However, he has observed that the majority of

Solar Geoengineering Impacts

Unraveling Solar Geoengineering’s Hidden Impacts

As we continue to face the repercussions of climate change, scientists and experts seek innovative ways to mitigate its impacts. Solar geoengineering (SG), a technique involving the distribution of aerosols

Razer Discount

Unbelievable Razer Blade 17 Discount

On September 24, 2023, it was reported that Razer, a popular brand in the premium gaming laptop industry, is offering an exceptional deal on their Razer Blade 17 model. Typically