Friday, August 31, 2012

Bit fields as text in Infragistics UltraWinGrid

If you receive a bit field from database and want to show some text (Yes/No in this example), instead of checkboxes here is the solution. First you need a class that implements the Infragistics.Win.IEditorDataFilter interface. Here is my implementation:
  1. using System;
  2. using System.Windows.Forms;
  3. using Infragistics.Win;
  4.  
  5. namespace dbMotion.DAT {
  6. internal class GridCheckBoxDataFilter:IEditorDataFilter {
  7. #region IEditorDataFilter Members
  8.  
  9. object IEditorDataFilter.Convert(EditorDataFilterConvertArgs args) {
  10. switch (args.Direction) {
  11. case ConversionDirection.EditorToOwner:
  12. args.Handled = true;
  13. args.IsValid = true;
  14. CheckState state = (CheckState) args.Value;
  15. switch (state) {
  16. case CheckState.Checked:
  17. return "Yes";
  18. case CheckState.Unchecked:return "No";
  19. case CheckState.Indeterminate:return string.Empty;
  20. } break;
  21. case ConversionDirection.OwnerToEditor:args.Handled = true;
  22. args.IsValid = true;
  23. return args.Value.ToString() == bool.TrueString ? "Yes" : "No";
  24. case ConversionDirection.DisplayToEditor:args.Handled = true;
  25. args.IsValid = true;
  26. return args.Value.ToString() == "Yes";
  27. case ConversionDirection.EditorToDisplay:args.Handled = true;
  28. args.IsValid = true;
  29. return args.Value;
  30. } throw new Exception("Invalid value passed into GridChecBoxDataFilter.Convert()");
  31. }
  32.  
  33. #endregion
  34. }
  35. }
  36.  
And after this add the following code to the "InitializeLayout" event of your UltraWinGrid:
  1. private void Grid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
  2. {
  3. e.Layout.Bands[0].Columns["Col1"].Editor = new EditorWithText();
  4. e.Layout.Bands[0].Columns["Col1"].Style = ColumnStyle.FormattedText;
  5. e.Layout.Bands[0].Columns["Col1"].Editor.DataFilter = new GridCheckBoxDataFilter();
  6. }
  7. }
  8.  

Tuesday, March 6, 2012

Multiselect dropdown/combobox

In my current project i need a dropdown list where user can pick multiple items and then, after double-clickin on any of selected items, all of them appears in the tex area of dropdown. There is no standard controls that are offering this functionality, so i did it by hand. It's not something uniqe, i saw some samples on the web, but thi one is done using Infragistics controls for Windows forms and is relatively easy to implement. So here is the code (just one file)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Infragistics.Win;
using Infragistics.Win.UltraWinEditors;
using Infragistics.Win.UltraWinListView;

namespace MyControls
{
    public partial class MultiSelectComboBox : UltraTextEditor
    {
        private UltraListView lv;


        public MultiSelectComboBox()
        {
            InitializeComponent();
            SetTextEditorProperties();
        }

        public MultiSelectComboBox(IContainer container)
        {
            container.Add(this);
            InitializeComponent();
            SetTextEditorProperties();
        }

        public UltraListViewItemsCollection ListItems
        {
            get { return lv.Items; }
        }

        private void SetTextEditorProperties()
        {
            DropDownEditorButton button = new DropDownEditorButton();
            lv = new UltraListView();
            lv.AutoSize = false;
            lv.Width = Width;
            lv.View = UltraListViewStyle.List;
            lv.ViewSettingsList.ImageSize = Size.Empty;
            lv.ViewSettingsList.ColumnWidth = Width;
            lv.ViewSettingsList.MultiColumn = false;
            lv.DoubleClick += lv_DoubleClick;
            lv.Width = Size.Width;
            button.ButtonStyle = Infragistics.Win.UIElementButtonStyle.Office2010ScrollbarButton;
            button.Control = lv;
            ButtonsRight.Add(button);
            Enabled = true;
            UseFlatMode = DefaultableBoolean.True;
        }

        private void lv_DoubleClick(object sender, EventArgs e)
        {
            UltraListView listView = sender as UltraListView;
            if (listView == null)
            {
                return;
            }
            string result = string.Empty;
            foreach (var item in listView.Items)
            {
                if (!string.IsNullOrEmpty(item.Text) && item.IsSelected)
                {
                    result += item.Text + ";";
                }
            }
            Text = result.Remove(result.Length - 1, 1);
            DropDownEditorButton btn = ButtonsRight[0] as DropDownEditorButton;
            if (btn != null)
            {
                btn.CloseUp();
            }
        }

        #region Methods

        public void LoadControl(List<string> items)
        {
            lv.Items.Clear();
            lv.Width = Size.Width;
            Enabled = false;
            if (items == null)
            {
                return;
            }
            if (items.Count == 0)
            {
                return;
            }
            Enabled = true;
            try
            {
                lv.Items.Add(new UltraListViewItem(string.Empty));
                foreach (var item in items)
                {
                    if (!lv.Items.Exists(item))
                    {
                        lv.Items.Add(item, item);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public void LoadControl(object[] items)
        {
            try
            {
                List<string> list = new List<string>();
                list.AddRange(items.Select(t => t.ToString()));
                LoadControl(list);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        #endregion
    }
}

Thursday, March 17, 2011

Хочу на DevCon'11

Страдаю программизмом уже больше 6 лет. Но все как-то варюсь в собственном соку, а душа, знаете-ли жаждет общения. Да еще суровая реальность жизни не позволяет объять необъятное, а иногда так хочется. Народ с завидной регулярностью придумывает все новые и новые, часто интересные и иногда очень полезные вещи, и остается только узнавать о них по заголовкам новостей. А так чтобы руками потрогать - это редко. А уж поговорить с теми кто все это придумал - еще реже. Вот и тянет меня на людей посмотреть, да послушать, ума-разума набраться в том месте, где нога моя не стояла, но куда я бы с удовольствием плюхнулся всем весом.


Или просто ссылка

Monday, December 6, 2010

Governemetn and open source

Australian citizens are trying to make all government IT software open source. The motivation is: as this software is developed using state budget and this budget is taxes (everyone pays it) so this software should be accessible for everyone

Friday, November 12, 2010

Update Samsung Vibrant from android 2.1 (Eclair) to android 2.2 (Froyo). My own experience

I recommend to read this post till the end and make your decision about upgrade after careful reading. Do not repeat my mistakes.

3 days ago i finally received my brand new Samsung Vibrant phone. Thanks to a very good Ebay seller.
Out-of-the-box Vibrant (currently) has android 2.1 (Eclair) but android 2.2 is available and contains many bug fixes and improvements. So, update is the option. But it isn't so easy.
First, Samsung Kies for Galaxy S 9000 does not recognize the phone. There is special version, but i haven't tried it yet. In any case there is no official update to android 2.2 (Froyo) from Samsung or T-Mobile. After little googling i found a good how-to. But there is always some "but". It's for Galaxy S. What's the problem, can you ask? Vibrant is Galaxy S! Not 100% as i discovered. I recommend you to read this post and comments too. Some answers are there, some in my post.
So, let's start.
First thing to check is if your phone supports three-keys command to switch to recovery mode:
1.Turn off the phone.
2.Hold volume up and volume down keys and then hold power-on key.
3.You will see "Vibrant" on your screen. for 3-4 seconds. Keep holding three key until you'll see yellow messages. Release buttons.
4.You should see a blue menu. Restart the phone.
5. Turn off the phone (neither by restarting and then switching it off or by pulling the battery out and reinserting it).

Second
, firmware itself. DO NOT UPDATE WITH FIRMWARE FOR GALAXY S!
Do not use i9000XXJP2 or any other listed on this site. This site requires registration to download. They listed T959UVJI2, T959UVJI4, T959UVJI6 as firmware for "Vibrant" but they are for Galaxy S. Only T959UVJFD is valid for "Vibrant" but it's the same firmware (2.1) that the phone has already.
I found this unofficial firmware (TMO) that is really good. And it works great. There is another one (MacnutR10) from the same team but i haven't tried it. So, go to see one of this and read the description VERY CAREFULLY.
Later i describe my experience of updating with TMO.
Third, Downloading mode. ATTENTION, DO NOT TRY IT NOW (will explain shortly). To enter to downloading mode, turn off your phone and press the volume up button and power button. If it does not help, pull off the battery, press those keys and with keys pressed insert the battery. Once in downloading mode, you cannot switch back to normal working mode (at least i haven't found the way) so there is no option but upgrade your firmware. While in downloading mode you should see a droid in yellow triangle.

So let's begin.

You need 3 packages: firmware (your choice TMO or MacnutR10), Odin3 1.7 (upgrade tool) and pit file (not always applicable, but ...). Download all.

ATTENTION Firmware update erases anything in your phone. So you cannot revert to factory-installed operating system. No recovery. After upgrading factory reset means that you will have a clean copy (without applications that you have installed and without all you data) of new firmware.

1. Connect your Vibrant to your PC with the USB cable and set USB Debugging On (System > Applications > Development > USB Debugging.). Very important step.

2. Remove the battery, SIM card and MicroSD card from your phone and reinsert the battery. Do it. You can lose anything on your SD card and I like very much the "Avatar" so i don't want to lose it.

3. Open Odin 3 v1.0

4. Click on the PIT button and load the “s1_odin_20100512.pit” file

5. Click on the PDA button and load the “Eugene_2E_JK2_Froyo.tar.md5”.

6. DO NOT check repartition check box (as stated in the FAQ for TMO)

7. Most important part. You should have your Odin ready to start (so check steps 4-6 once again). Also insert your usb cable into your computer but not in the phone! Switch you phone in downloading mode and then connect the usb cable. In 3-4 seconds you will see a yellow COM port number in Odin. Hit the "Start" button immediately.
You will have problem if you plug in the phone before setting up Odin. Odin will see your phone but will stuck on connection phase. So be fast. If you will have problem, try to pull off the battery, hold volume up and power keys, insert the battery and plug in the cable, wait for yellow COM port number and hit "Start" again.
If everything is OK then you will see the green progress bar in Odin and a cyan progress bar on your phone.

8. There is no Sims3 in this firmware, you can find the apk file here. Works perfectly with TMO firmware

9. Enjoy

DO NOT REPEAT MY MISTAKES

1. Just try to enter to downloading mode. I have tried and successfully but after i discovered that i cannot switch back. I unplugged the battery and inserted it again but the only thing I saw was the icon of phone and computer and orange triangle between them. Nothing more. Pressing on any keys didn't help. At this moment I pissed off for the first time. My brand new Vibrant was inoperable.
2. Thanks God I had my Odin prepared with i9000XXJP2 firmware and just by coincidence i did the right sequence. Holding volume up key and power key I plugged in the battery, then my phone to the computer and hit "Start" in Odin. And downloading started. "Thanks God" I said, but...
3. After loading this firmware phone showed me that he is Samsung Galaxy S (not Vibrant) and the only thing available was the recovery mode. There is a subtle difference between them

Vibrant









Galaxy S



No "OK" key on Vibrant (this huge key in the center of Galaxy S).
So the only option for me was to watch this recovery screen and restart phone bu pulling of and reinserting the battery. I pissed off for the second time.

3. Now, really thanks to Samsung engineers, switch to downloading mode worked! Even with wrong firmware. But there is Odin too. Being pissed off two times I switched to downloading mode and plugged the phone into my computer. And waited 20 minutes for new firmware to complete downloading. Then i started Odin, but Odin haven't found any phone. Unplug and plug back to the computer helped and i started to setting up Odin. After I hit the "Start" key and after few seconds I saw "Connecting" in the log screen. But it stuck on it (I have unplugged the phone after 15 minutes of waiting). And, as you can guess, I pissed off for the third time.

4. Thanks to google i found the info about fast plugging the phone and starting the update. But it was a piss off day.

Remember, anything you do you are doing on your own risk


Any suggestions, comments and improvements are welcome

Sunday, November 7, 2010