Exemplo n.º 1
0
        public string GetVirtrueValue()
        {
            string ret = string.Empty;

            foreach (Control control in Controls)
            {
                if (control is CheckBox)
                {
                    CheckBox checkBox = control as CheckBox;
                    if (checkBox.Checked)
                    {
                        string tvalue = checkBox.Text;

                        IndexLeftMarginPair index = checkBox.Tag as IndexLeftMarginPair;
                        if (_dataRows != null && index != null && _dataRows.Length > index.Index && !string.IsNullOrEmpty(_valueFieldName))
                        {
                            if (_dataRows[index.Index][_valueFieldName] != DBNull.Value)
                            {
                                tvalue = _dataRows[index.Index][_valueFieldName].ToString();
                            }
                        }
                        ret += "," + tvalue;
                    }
                }
            }
            if (!string.IsNullOrEmpty(ret))
            {
                ret = ret.Substring(1);
            }
            return(ret);
        }
Exemplo n.º 2
0
 private void SetMulitValue(string value)
 {
     if (_dataRows != null && _dataRows.Length > 0)
     {
         string vField = _valueFieldName;
         if (string.IsNullOrEmpty(vField) && _defaultItems != null && _defaultItems.Count > 0)
         {
             vField = "ITEM_VALUE";
         }
         if (!string.IsNullOrEmpty(vField))
         {
             List <int> list = new List <int>();
             if (value != null)
             {
                 string v = "," + value + ",";
                 for (int i = 0; i < _dataRows.Length; i++)
                 {
                     if (_dataRows[i][vField] != System.DBNull.Value && v.Contains("," + _dataRows[i][vField].ToString() + ","))
                     {
                         list.Add(i);
                     }
                 }
             }
             foreach (Control control in Controls)
             {
                 if (control is CheckBox)
                 {
                     (control as CheckBox).Checked = false;
                 }
             }
             if (list.Count > 0)
             {
                 foreach (int index in list)
                 {
                     foreach (Control control in Controls)
                     {
                         if (control is CheckBox)
                         {
                             IndexLeftMarginPair indexPair = control.Tag as IndexLeftMarginPair;
                             if (indexPair != null && index == indexPair.Index)
                             {
                                 (control as CheckBox).Checked = true;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        private void SetList()
        {
            Font _font = this.Font;

            Controls.Clear();
            Control control = null;
            int     top = 0, left = 0;
            int     maxWidth = Width - xOffSet;

            if (_dataRows != null)
            {
                for (int index = 0; index < _dataRows.Length; index++)
                {
                    if (_displayFieldName == null)
                    {
                        _displayFieldName = "ITEM_NAME";
                    }
                    string text = _dataRows[index][_displayFieldName].ToString();
                    IndexLeftMarginPair indexLeftPair = new IndexLeftMarginPair();
                    control = new CheckBox();
                    CheckBox checkBox = control as CheckBox;
                    checkBox.AutoSize   = false;
                    checkBox.Text       = text;
                    indexLeftPair.Index = index;
                    checkBox.Click     += new EventHandler(checkBox_Click);
                    checkBox.Paint     += new PaintEventHandler(checkBox_Paint);
                    control.Font        = _font;
                    control.ForeColor   = ForeColor;
                    control.Name        = string.Format("Control{0}", new object[] { index });
                    using (Graphics g = control.CreateGraphics())
                    {
                        SizeF measuerSize = g.MeasureString(text, _font);
                        control.Top    = top;
                        control.Left   = left;
                        control.Width  = xOffSet + (int)Math.Ceiling(measuerSize.Width) + (_font.Style == FontStyle.Bold ? 10 : 0);
                        control.Height = (int)Math.Ceiling(measuerSize.Height) + 1;

                        if (_isVert)
                        {
                            if (_checkBoxLocation == LeftRightAlignment.Left)
                            {
                                checkBox.CheckAlign = ContentAlignment.TopLeft;
                            }
                            else
                            {
                                checkBox.CheckAlign = ContentAlignment.TopRight;
                                checkBox.TextAlign  = ContentAlignment.MiddleRight;
                                checkBox.Left      += Width - checkBox.Width;
                            }
                            // 判断总共需要几行
                            if (measuerSize.Width > maxWidth)
                            {
                                int nLines  = Convert.ToInt32(Math.Ceiling(measuerSize.Width)) / maxWidth;
                                int nRemain = Convert.ToInt32(Math.Ceiling(measuerSize.Width)) % maxWidth;
                                if (nRemain > 0)
                                {
                                    nLines++;
                                }
                                control.Width  = Width;
                                control.Height = control.Height * nLines;
                            }
                            top += control.Height + 2;
                        }
                        else
                        {
                            if (_checkBoxLocation == LeftRightAlignment.Left)
                            {
                                checkBox.CheckAlign = ContentAlignment.MiddleLeft;
                            }
                            else
                            {
                                checkBox.CheckAlign = ContentAlignment.MiddleRight;
                            }
                            // 如果选项一行装不下,则分多行
                            if (measuerSize.Width > maxWidth)
                            {
                                if (left > 0)
                                {
                                    top += control.Height + 3;
                                }
                                control.Left = left = 0;
                                control.Top  = top;
                                // 判断总共需要几行
                                int nLines  = Convert.ToInt32(Math.Ceiling(measuerSize.Width)) / maxWidth;
                                int nRemain = Convert.ToInt32(Math.Ceiling(measuerSize.Width)) % maxWidth;
                                if (nRemain > 0)
                                {
                                    nLines++;
                                }
                                control.Width  = Width;
                                control.Height = control.Height * nLines;
                                top           += control.Height + 3;
                            }
                            else if (left + measuerSize.Width > maxWidth)  // 本行不够则换行
                            {
                                control.Left = 0;
                                top         += control.Height + 3;
                                control.Top  = top;

                                left = control.Width;
                            }
                            else
                            {
                                left += control.Width;
                            }
                        }
                        if (_dataRows[index]["LeftMargin"] != null && _dataRows[index]["LeftMargin"] != DBNull.Value && !(_dataRows[index]["LeftMargin"] is DBNull))
                        {
                            int leftMargin = Convert.ToInt32(_dataRows[index]["LeftMargin"]);

                            if (leftMargin > 0)
                            {
                                if (_isVert)
                                {
                                    control.Top += leftMargin;
                                    top         += leftMargin;
                                }
                                else
                                {
                                    if (control.Left + leftMargin + measuerSize.Width > maxWidth)
                                    {
                                        control.Left = 0;
                                        top         += control.Height + 3;
                                        control.Top  = top;
                                        left         = control.Width;
                                    }
                                    else
                                    {
                                        control.Left += leftMargin;
                                        left         += leftMargin;
                                    }
                                }

                                indexLeftPair.LeftMargin = leftMargin;
                            }
                        }
                        control.Tag = indexLeftPair;
                        Controls.Add(control);
                    }
                }
            }
            if (Controls.Count > 0)
            {
                toolTip1.SetToolTip(this, null);
            }
        }
Exemplo n.º 4
0
        private void checkBox_Click(object sender, EventArgs e)
        {
            if (_readOnly)
            {
                (sender as CheckBox).Checked = !(sender as CheckBox).Checked;
                return;
            }
            else
            {
            }
            string value = "";

            _simpleValue = null;
            foreach (Control control in Controls)
            {
                if (control is CheckBox)
                {
                    CheckBox checkBox = control as CheckBox;
                    if (!_multiSelect)
                    {
                        if (!checkBox.Equals(sender))
                        {
                            checkBox.Checked = false;
                        }
                    }
                    if (checkBox.Checked)
                    {
                        string tvalue = checkBox.Text;
                        if (!_multiSelect)
                        {
                            IndexLeftMarginPair index = checkBox.Tag as IndexLeftMarginPair;
                            if (_dataRows != null && index != null && _dataRows.Length > index.Index && !string.IsNullOrEmpty(_valueFieldName))
                            {
                                _simpleValue = _dataRows[index.Index][_valueFieldName];
                            }
                        }
                        else
                        {
                            IndexLeftMarginPair index = checkBox.Tag as IndexLeftMarginPair;
                            if (_dataRows != null && index != null && _dataRows.Length > index.Index && !string.IsNullOrEmpty(_valueFieldName))
                            {
                                if (_dataRows[index.Index][_valueFieldName] != DBNull.Value)
                                {
                                    tvalue = _dataRows[index.Index][_valueFieldName].ToString();
                                }
                            }
                        }
                        value += "," + tvalue;
                    }
                }
            }
            if (!string.IsNullOrEmpty(value))
            {
                value = value.Substring(1);
            }
            if (!value.Equals(_value))
            {
                _value = value;
            }
            RaiseValueChanged();
        }