Speaking dotNet environment control function xtraGrid

Devexpress company has two of its localization methods recommended, this is a stupid way to achieve here when I did not start its deep understanding, has been placed here, continue stood it , unfortunately I do not understand why a Download Help no details in this regard, rather than go to its web site to find information for the job.

Powerful and easy to use controls xtraGrid Needless to say, the database did the people should know. Many parts of it which is presented to the user of the English way, which makes us need to look it up in the culture. Or how presented to the user ah. After more than 1 day of agonizing, sweat, mainly due to dotNet is not yet ripe, no matter how, easy Ye Hao, hard or, finally toss out. I used to have achieved part of the culture. Now published the following code, the use of very simple, just call it chineseXtraGrid (DevExpress.XtraGrid.GridControl) where appropriate
function on the line. Did not realize how specific content is optimized for a friend in need and then feel free to go their own modify it. That there is no better way or suggestions, we hope to give me a message.

Environment: C #, xtraGridV3, control package version 2.0.6

#region  汉化xtraGrid部分
  
  public void chineseXtraGrid(DevExpress.XtraGrid.GridControl xg)
  {
   //汉化MainView
   if(xg.LevelTree.LevelTemplate.GetType().Equals(typeof(DevExpress.XtraGrid.Views.Grid.GridView)))
    chineseView((DevExpress.XtraGrid.Views.Grid.GridView)xg.LevelTree.LevelTemplate);
   //汉化子View,即PartenViews
   enumAllViews(xg.LevelTree.Nodes);
  }

  private void enumAllViews(DevExpress.XtraGrid.GridLevelNodeCollection nodeColl)
  {   
   foreach (DevExpress.XtraGrid.GridLevelNode node in nodeColl) {
                if(node.LevelTemplate.GetType().Equals(typeof(DevExpress.XtraGrid.Views.Grid.GridView)))
    {     
     chineseView((DevExpress.XtraGrid.Views.Grid.GridView)node.LevelTemplate);
     if (node.HasChildren)
      enumAllViews(node.Nodes);
    }
   }
  }

  private void chineseView(DevExpress.XtraGrid.Views.Grid.GridView gv)
  {
   gv.OptionsView.ShowAutoFilterRow = true;
#if DEBUG
   gv.OptionsView.ShowFilterPanel = true; 
#else
     gv.OptionsView.ShowFilterPanel = false; 
#endif
   gv.OptionsFilter.ColumnFilterPopupMaxRecordsCount = 0; //不显示所有记录值
   gv.GroupPanelText = "拖动列头到这里实现分组";
   gv.ShowGridMenu += new DevExpress.XtraGrid.Views.Grid.GridMenuEventHandler(gridView_ShowGridMenu);
   gv.GridMenuItemClick += new DevExpress.XtraGrid.Views.Grid.GridMenuItemClickEventHandler(gridView_GridMenuItemClick);
   gv.ShowFilterPopupListBox += new DevExpress.XtraGrid.Views.Grid.FilterPopupListBoxEventHandler(gridView_ShowFilterPopupListBox);
   gv.CustomFilterDialog += new DevExpress.XtraGrid.Views.Grid.CustomFilterDialogEventHandler(gridView_CustomFilterDialog);
  }

  private void gridView_CustomFilterDialog(object sender, DevExpress.XtraGrid.Views.Grid.CustomFilterDialogEventArgs e)
  {   
   DevExpress.XtraGrid.Filter.FilterCustomDialog dlg = new DevExpress.XtraGrid.Filter.FilterCustomDialog(e.Column);
   dlg.Text = "自定义筛选窗口";   
   chineseControl(dlg);
   dlg.ShowDialog();
   e.FilterInfo = null;
   e.Handled = true;
  }
  private Control GetChildControlByName(Control.ControlCollection cc, String sname)
  {
   Control  cl = null;
   foreach(Control ctrl in cc)
   { 
    if ((cl == null) && sname.Equals(ctrl.Name))
     cl = ctrl;
    else if (ctrl.HasChildren)
     cl = GetChildControlByName(ctrl.Controls, sname);    

    if (cl != null) break;
   }
   return cl;
  }
  private void SelectedIndexChanged(object sender, System.EventArgs e)  
  {
   DevExpress.XtraEditors.ComboBoxEdit newc = sender as  DevExpress.XtraEditors.ComboBoxEdit;
   DevExpress.XtraEditors.ComboBoxEdit cc = newc.Tag as DevExpress.XtraEditors.ComboBoxEdit;
   cc.SelectedIndex = newc.SelectedIndex;
  }
  private System.Collections.Specialized.ListDictionary filterDic;

  private void chineseControl(Control ctrl)
  { 
   if (filterDic == null) {
    filterDic = new System.Collections.Specialized.ListDictionary();    
    filterDic.Add("",   "");
    filterDic.Add("等于=",  "equals");
    filterDic.Add("不等于<>", "does not equal");
    filterDic.Add("大于>",  "is greater than");
    filterDic.Add("大于或等于>=","is greater than or equal to");
    filterDic.Add("小于<",  "is less than");
    filterDic.Add("小于或等于<=","is less than or equal to");
    filterDic.Add("空值NULL", "blanks");
    filterDic.Add("非空值Not NULL","non blanks");
    filterDic.Add("包含Like",   "like");
    filterDic.Add("不包含Not Like","not like");
   }
   Control child = GetChildControlByName(ctrl.Controls, "btnCancel");
   if (child != null)
    child.Text = "取消";
   child = GetChildControlByName(ctrl.Controls, "btnOK");
   if (child != null)
    child.Text = "确定";
   child = GetChildControlByName(ctrl.Controls, "rbOr");
   if (child != null)
    child.Text = "或";
   child = GetChildControlByName(ctrl.Controls, "rbAnd");
   if (child != null)
    child.Text = "与";
   child = GetChildControlByName(ctrl.Controls, "label1");
   if (child != null)
    child.Text = "条件:";
   child = GetChildControlByName(ctrl.Controls, "piFirst");
   if (child != null)
    chineseComboEdit(child);
   child = GetChildControlByName(ctrl.Controls, "piSecond");
   if (child != null)
    chineseComboEdit(child);
  }

  private void chineseComboEdit(Control ctrl)
  {
   DevExpress.XtraEditors.ComboBoxEdit newc = new  DevExpress.XtraEditors.ComboBoxEdit();
   newc.Name = ctrl.Name +"clone";    
   ctrl.Parent.Controls.Add(newc);    
   newc.Location = ctrl.Location;
   newc.Size = ctrl.Size;       
   ctrl.Visible = false;
   newc.Tag = ctrl;
   newc.Visible = true;
   DevExpress.XtraEditors.Controls.ComboBoxItemCollection coll = newc.Properties.Items;    
   foreach ( DictionaryEntry de in filterDic )
   {
    coll.Add(de.Key);
   }    
   newc.SelectedIndex = (ctrl as DevExpress.XtraEditors.ComboBoxEdit).SelectedIndex;
   newc.SelectedIndexChanged += new System.EventHandler(SelectedIndexChanged);   
  }

  private void gridView_ShowFilterPopupListBox(object sender, DevExpress.XtraGrid.Views.Grid.FilterPopupListBoxEventArgs e)
  {   
   for(int i = 0; i < e.ComboBox.Items.Count; i++)
   {
    object item = e.ComboBox.Items[i];
    if(item is DevExpress.XtraGrid.Views.Grid.FilterItem && ((DevExpress.XtraGrid.Views.Grid.FilterItem)item).Value is DevExpress.XtraGrid.Views.Grid.FilterItem)
    {
     object itemValue2 = ((DevExpress.XtraGrid.Views.Grid.FilterItem)((DevExpress.XtraGrid.Views.Grid.FilterItem)item).Value).Value;
     
     if(itemValue2 is Int32)
     {
      switch(Convert.ToInt32(itemValue2))
      {
       case 0:
        (e.ComboBox.Items[i] as DevExpress.XtraGrid.Views.Grid.FilterItem).Text = "所有";
        break;
       case 1:
        (e.ComboBox.Items[i] as DevExpress.XtraGrid.Views.Grid.FilterItem).Text = "自定义";
        break;
       case 2:
        (e.ComboBox.Items[i] as DevExpress.XtraGrid.Views.Grid.FilterItem).Text = "空值";   
        break;
       case 3:
        (e.ComboBox.Items[i] as DevExpress.XtraGrid.Views.Grid.FilterItem).Text = "非空值";
        break;
      }
     }
    }
   }
  }

  private void gridView_GridMenuItemClick(object sender, DevExpress.XtraGrid.Views.Grid.GridMenuItemClickEventArgs e)
  {
   //汉化xtraGrid的统计菜单格式      
   if(e.MenuType !=  DevExpress.XtraGrid.Views.Grid.GridMenuType.Summary) return;
   
   String  strFormat = e.SummaryFormat;
   int equInx = strFormat.IndexOf("=");
   if (equInx > 0)
   {
    strFormat = e.DXMenuItem.Caption + strFormat.Substring(equInx);
    e.SummaryFormat = strFormat;
   }
  }
  private void gridView_ShowGridMenu(object sender, DevExpress.XtraGrid.Views.Grid.GridMenuEventArgs e)
  { 

//------------------------------------------------------------------------------------------------------------//

// This code is specific to a xtrGrid I add a point hollow place when displaying the menu, I am here to join its print function
  IF (e.Menu == null)
   {

/*
    if(e.HitInfo.InRow == false && (sender is DevExpress.XtraGrid.Views.Grid.GridView))
    {
     gCExport = ((DevExpress.XtraGrid.Views.Grid.GridView)sender).GridControl;               
     Point pt = e.Point;
     pt.X = pt.X + gCExport.Location.X;
     pt.Y = pt.Y + gCExport.Location.Y;
     popupMenu1.ShowPopup(gCExport.PointToScreen(pt));     
    }        

*/
    return;
   }

//------------------------------------------------------------------------------------------------------------//
   //汉化xtraGrid的菜单
   System.Collections.Specialized.ListDictionary ld = new System.Collections.Specialized.ListDictionary();
   ld.Add(DevExpress.XtraGrid.Localization.GridStringId.MenuFooterSum, "总和");
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuFooterMin,"最小值");
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuFooterMax,"最大值");
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuFooterCount,"数量");
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuFooterAverage,"平均值");
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuFooterNone,"无");
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuColumnSortAscending,"上升排序");
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuColumnSortDescending,"下降排序");
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuColumnGroup,"分组");
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuColumnUnGroup,"取消分组");     
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuColumnColumnCustomization,"自定义");
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuColumnBestFit,"最佳宽度");
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuColumnFilter,"过滤");
   ld.Add( DevExpress.XtraGrid.Localization.GridStringId.MenuColumnClearFilter,"清除过滤");
   ld.Add (DevExpress.XtraGrid.Localization.GridStringId.MenuColumnBestFitAllColumns, "optimum width of all columns");
   ld.Add (DevExpress.XtraGrid.Localization.GridStringId.MenuGroupPanelFullExpand, "Expand All");
   ld.Add (DevExpress.XtraGrid .Localization.GridStringId.MenuGroupPanelFullCollapse, "all shrinkage");
   ld.Add (DevExpress.XtraGrid.Localization.GridStringId.MenuGroupPanelClearGrouping, "clear packet");
   ld.Add (DevExpress.XtraGrid.Localization.GridStringId.MenuColumnGroupBox, "windowed packet ");

   foreach (DevExpress.Utils.Menu.DXMenuItem  item in e.Menu.Items)
   {    
    Object val = ld[item.Tag];
    if (val != null)    
     item.Caption = val.ToString();    
    
   }
  }
#endregion

Published 30 original articles · won praise 2 · views 50000 +

Guess you like

Origin blog.csdn.net/khzide/article/details/578336