Archive for the 'Work' Category

C# Listbox flickering, do not use height property

I’ve created a new ASP.NET 2.0 page, inherited a menu bar from a master page and put a listbox that is binded to a dataset. Whenever I move my mouse cursor over the menu bar, the listbox would flicker. Googling the term “C# listbox flicker” yeild solutions such as Double Buffering, custom control, .BeginUpdate and .EndUpdate, just to name a few.

And then it struck me. I tested the same page in Firefox, and the list only displayed 18.5 rows. Yes, half a row, IE6 displayed 19 full rows. That tells me it has something to do with the height property. Sure enough, remove the Height property and instead put in a specific number of rows in the Rows property solved the problem.

Reference: Vikram Lakhotia

Problems with DataGridView control in C#

So I was having problems with DataGridView control.  I created a DataGridView and have added a collection of columns that corresponds to the columns in my custom object.

The I binded my custom object to the DataSource programmatically in my code, but for the life of me, I couldn’t work out why it is not displaying in the grid.  After spending something like an hour stepping through my code, I finally figured it out.  I need to enter the column name in the DataPropertyName.

You can do that in Designer View.  Right-click on the DataGridView control and select Edit Column.  Select the column you want, and set the DataPropertyName to the column name that is in your custom object.

A little example, you have a People object that has one property – Name, and you want to bind People to DataGridView1.

1) Create DataGridView1 control on the form
2) Right click on DataGridView1 and “Add…” column Name (or whatever you want).
3) Here is the most important bit.  In your Name column, there is a property called DataPropertyName.  Type “Name” in it.  This has to match the property name of your object.
4) Create a custom object People.
5) In your code, bind your DataSource to the People object.  Probably look something like this: DataGridView1.DataSource = People;

There you have it.

BTW, I have turned off AutoGenerateColumns.  That could be another reason why my values weren’t showing up.

Training Camp

Finally arrived back in town after 3 days of going interstate for my training on some software that my company is using. The training was quite interesting, and for once, I actually understood what was being taught. Well, ‘taught’ is not quite the right word. You see, unlike a formal training centre, my training was conducted in a 3m x 6m meeting room of the software vendor. The table was barely big enough to fit the six of us. The instructor is done with the theory in the first 2 hours of the first day. And the rest of the course was just doing exercises.

They might as well, because the phones of the other trainees were constantly ringing. Everyone had their own laptop setup in the meeting room. It was as though all these people are so important to their companies that they can’t be left alone for 3 days, stuffed with five other people in a room and do the training. I felt so left out. Then one day my phone rang. I remembered myself thinking ‘Finally, I can feel my importance to the company. They can’t live without me.’ And then it turned out to be just a friend. How disappointing.

Frankly, it could have been done online. But who am I to complain when it is all paid for by the company? And talking about trip, it has to be one of the most eventful Tuesday morning I have had for…. like, ever.

Flying out

So I’m off to interstate next week for a training course in a software package that our company is currently using (or will use in the future). I have been to several training courses during my time with the company, but never more than 100km away from my workplace, let along 1,000km.

This is the first time I’m running off on business. I’m both excited and worried. Excited because it’s my first time, but a little worried because I don’t know what to expect. What’s more is what is paid for by the company? I am certain as hell not going to pay for transport or dinner. Hopefully the training place will provide lunch.

Nothing is free, but whatever it cost, it is not coming out of my own pocket.



Follow

Get every new post delivered to your Inbox.