DataGridView中的ComboBoxItems文字過長,顯示不全對應策
                  //----------------------------------------------------
                  /// <summary>
                  
          /// BDataGridView cell enters edit mode 時発生します
                  
          /// </summary>
                  
          /// <param name="sender"></param>
                  
          /// <param name="e"></param>
                  //----------------------------------------------------
                  private void bDgvToti_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
                  {
                      ComboBox cmb = e.Control as ComboBox;
                      if (cmb != null)
                      {
                          cmb.DropDown -= new EventHandler(bDgvCmb_DropDown);
                          cmb.DropDown += new EventHandler(bDgvCmb_DropDown);
                      }
                  }

                  //----------------------------------------------------
                  /// <summary>
                  
          /// auto-size the DataGridViewComboBoxColumns's DropDownWidth
                  
          /// </summary>
                  
          /// <param name="sender"></param>
                  
          /// <param name="e"></param>
                  //----------------------------------------------------
                  private void bDgvCmb_DropDown(object sender,EventArgs e)
                  {
                      ComboBox cmb = sender as ComboBox;
                      int width = cmb.DropDownWidth;
                      Graphics g = cmb.CreateGraphics();
                      Font font = cmb.Font;
                      int vertScrollBarWidth = 0;
                      if (cmb.Items.Count > cmb.MaxDropDownItems)
                          vertScrollBarWidth = SystemInformation.VerticalScrollBarWidth;

                      int maxWidth;
                      foreach (DataRowView drv in cmb.Items)
                      {
                          string s = drv[0].ToString();
                          maxWidth = (int)g.MeasureString(s, font).Width + vertScrollBarWidth;
                          if (width < maxWidth)
                              width = maxWidth;
                      }

                      DataGridViewComboBoxColumn c =
                          this.bDgvToti.Columns[bDgvToti.CurrentCell.ColumnIndex] as DataGridViewComboBoxColumn;
                      if (c != null)
                          c.DropDownWidth = width;
                  }
          posted on 2016-04-07 15:16 Ying-er 閱讀(413) 評論(0)  編輯  收藏 所屬分類: .Net
          主站蜘蛛池模板: 大同县| 科技| 仙居县| 南和县| 邹平县| 泽州县| 福海县| 贵港市| 揭西县| 广西| 滁州市| 山阳县| 土默特左旗| 青川县| 抚松县| 金门县| 阆中市| 从江县| 天峨县| 宕昌县| 巧家县| 泾源县| 伊吾县| 南丹县| 南京市| 分宜县| 吉安市| 襄垣县| 淳化县| 京山县| 泰来县| 聂荣县| 淄博市| 徐州市| 安化县| 石家庄市| 长沙市| 广南县| 湟中县| 湟源县| 松滋市|