public KeyboardLayoutLanguagesList GetAutomaticLayouts()
        {
            KeyboardLayoutLanguagesList result = new KeyboardLayoutLanguagesList();

            for (int i = 1; i < (int)Language.Last; i++)
            {
                Language lng = (Language)i;
                foreach (InputLanguage il in InputLanguage.InstalledInputLanguages)
                {
                    if (InputLanguageManager.IsLanguageSupported(il, lng))
                    {
                        result.Add(il.LayoutName, lng);
                    }
                }
            }

            return(result);
        }
        void InitLangsToLayout()
        {
            DataTable dtLangs = dsMain.Tables["LangToLayouts"];
            bool      autoSupported;

            for (int i = 1; i < (int)Language.Last; i++)
            {
                Language lng = (Language)i;
                if (lng == Language.Autodetect)
                {
                    continue;
                }

                DataRow row = dtLangs.Rows.Find(lng);
                row["Auto"]    = true;
                row["Changed"] = false;

                autoSupported = false;
                foreach (InputLanguage il in InputLanguage.InstalledInputLanguages)
                {
                    if (InputLanguageManager.IsLanguageSupported(il, lng))
                    {
                        autoSupported = true;
                        string layoutName = il.LayoutName + il.Culture.EnglishName;
                        row["SavedLayout"] = layoutName;
                        row["Layout"]      = layoutName;
                        row["AutoLayout"]  = layoutName;
                        row["Auto"]        = true;
                        break;
                    }
                }
                if (!autoSupported)
                {
                    row["SavedLayout"] = dontchangeStr;
                    row["Layout"]      = dontchangeStr;
                    row["AutoLayout"]  = dontchangeStr;
                }
            }

            foreach (KeyboardLayoutLanguage kll in options.CustomLayouts)
            {
                if (layoutsKeys.ContainsKey(kll.LayoutName))
                {
                    DataRow row = dtLangs.Rows.Find(kll.Language);
                    row["SavedLayout"] = kll.LayoutName;
                    row["Layout"]      = kll.LayoutName;
                    row["Auto"]        = false;
                }
            }
            //DataView dv = dtLangs.DefaultView;
            //dv.Sort = "Layout DESC";
            //dgvLayouts.DataSource = dv;
            DataView dv = dtLangs.DefaultView;

            dv.Sort = "DisplayName";
            dgvLayouts.DataSource = dv;
            dgvLayouts.Invalidate();
            string tooltip;

            foreach (DataGridViewRow gvRow in dgvLayouts.Rows)
            {
                DataRowView rowView = gvRow.DataBoundItem as DataRowView;
                DataRow     row     = rowView.Row;
                row["Changed"]          = String.Compare((string)row["Layout"], (string)row["SavedLayout"], false, CultureInfo.InvariantCulture) != 0;
                row["Auto"]             = String.Compare((string)row["Layout"], (string)row["AutoLayout"], false, CultureInfo.InvariantCulture) == 0;
                gvRow.Cells[2].ReadOnly = (bool)row["Auto"];
                gvRow.Cells[3].ReadOnly = !(bool)row["Changed"];

                tooltip = GenerateTooltip(row);
                for (int i = 0; i < 4; i++)
                {
                    gvRow.Cells[i].ToolTipText = tooltip;
                }
            }
        }