Пример #1
0
        private void UpdateDataGrid(AttributeValue current)
        {
            m_dgvValues.Rows.Clear();
            m_cbxValue.Items.Clear();
            m_tbxKey.Text = current.Key;
            m_cbxValue.Text = AttributeValue.ConvertDataToString(current);
            m_cbxDataType.Text = s_typeNames[(int) current.DataType];
            if (current.DataType == AttributeDataType.Table)
            {
                m_dgvValues.AllowUserToAddRows = true;
                int index = -1;
                foreach (AttributeValue attribValue in (current.Data as AttributeTable))
                {
                    var currentRow = (DataGridViewRow) m_dgvValues.RowTemplate.Clone();
                    // setting up the cells
                    var keyCell = new DataGridViewTextBoxCell {Value = attribValue.Key};
                    currentRow.Cells.Add(keyCell);

                    DataGridViewCell value;
                    switch (attribValue.DataType)
                    {
                        case AttributeDataType.Boolean:
                            value = new DataGridViewCheckBoxCell {Value = (bool)attribValue.Data};
                            break;
                        case AttributeDataType.String:
                            // filling the dropdown boxes
                            value = new DataGridViewComboxCell();
                            var cell = (DataGridViewComboxCell) value;
                            cell.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
                            cell.Sorted = true;
                            if (index != -1 && m_dgvValues.Rows[index].Cells[0].Value.Equals(attribValue.Key))
                            {
                                var upperCell = m_dgvValues.Rows[index].Cells[1] as DataGridViewComboBoxCell;
                                if (upperCell != null)
                                    cell.Items.AddRange(upperCell.Items);
                            }

                            if (cell.Items.Count == 0)
                            {
                                // get preset-entries from the dictionary
                                cell.Items.AddRange(RBFDictionary.GetDictEntries(attribValue.Key));
                                // try to get strings from userpath -- else go search for paths on our own
                                GetPathsForComboBox(cell, attribValue.Key, attribValue.Data as string);
                            }
                            if (!cell.Items.Contains(attribValue.Data as string))
                                cell.Items.Add(attribValue.Data);
                            value.Value = AttributeValue.ConvertDataToString(attribValue);
                            break;
                        default:
                            value = new DataGridViewTextBoxCell {Value = AttributeValue.ConvertDataToString(attribValue)};
                            break;
                    }
                    currentRow.Cells.Add(value);

                    var type = new DataGridViewComboBoxCell();
                    type.Items.AddRange(new[] {"float", "int", "bool", "table", "string"});
                    type.Value = s_typeNames[(int) attribValue.DataType];
                    currentRow.Cells.Add(type);
                    type.ReadOnly = true;

                    index = m_dgvValues.Rows.Add(currentRow);
                    m_dgvValues.Rows[index].Tag = attribValue;
                }
            }
            else if (current.DataType == AttributeDataType.Boolean)
            {
                m_cbxValue.Items.Add("true");
                m_cbxValue.Items.Add("false");
            }
            m_dgvValues.Sort(m_dgvValues.Columns[0], ListSortDirection.Ascending);
        }
Пример #2
0
        private void UpdateDataGrid(AttributeValue current)
        {
            m_dgvValues.Rows.Clear();
            m_cbxValue.Items.Clear();
            m_tbxKey.Text      = current.Key;
            m_cbxValue.Text    = AttributeValue.ConvertDataToString(current);
            m_cbxDataType.Text = s_typeNames[(int)current.DataType];
            if (current.DataType == AttributeDataType.Table)
            {
                m_dgvValues.AllowUserToAddRows = true;
                int index = -1;
                foreach (AttributeValue attribValue in (current.Data as AttributeTable))
                {
                    var currentRow = (DataGridViewRow)m_dgvValues.RowTemplate.Clone();
                    // setting up the cells
                    var keyCell = new DataGridViewTextBoxCell {
                        Value = attribValue.Key
                    };
                    currentRow.Cells.Add(keyCell);

                    DataGridViewCell value;
                    switch (attribValue.DataType)
                    {
                    case AttributeDataType.Boolean:
                        value = new DataGridViewCheckBoxCell {
                            Value = (bool)attribValue.Data
                        };
                        break;

                    case AttributeDataType.String:
                        // filling the dropdown boxes
                        value = new DataGridViewComboxCell();
                        var cell = (DataGridViewComboxCell)value;
                        cell.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
                        cell.Sorted       = true;
                        if (index != -1 && m_dgvValues.Rows[index].Cells[0].Value.Equals(attribValue.Key))
                        {
                            var upperCell = m_dgvValues.Rows[index].Cells[1] as DataGridViewComboBoxCell;
                            if (upperCell != null)
                            {
                                cell.Items.AddRange(upperCell.Items);
                            }
                        }

                        if (cell.Items.Count == 0)
                        {
                            // get preset-entries from the dictionary
                            cell.Items.AddRange(RBFDictionary.GetDictEntries(attribValue.Key));
                            // try to get strings from userpath -- else go search for paths on our own
                            GetPathsForComboBox(cell, attribValue.Key, attribValue.Data as string);
                        }
                        if (!cell.Items.Contains(attribValue.Data as string))
                        {
                            cell.Items.Add(attribValue.Data);
                        }
                        value.Value = AttributeValue.ConvertDataToString(attribValue);
                        break;

                    default:
                        value = new DataGridViewTextBoxCell {
                            Value = AttributeValue.ConvertDataToString(attribValue)
                        };
                        break;
                    }
                    currentRow.Cells.Add(value);

                    var type = new DataGridViewComboBoxCell();
                    type.Items.AddRange(new[] { "float", "int", "bool", "table", "string" });
                    type.Value = s_typeNames[(int)attribValue.DataType];
                    currentRow.Cells.Add(type);
                    type.ReadOnly = true;

                    index = m_dgvValues.Rows.Add(currentRow);
                    m_dgvValues.Rows[index].Tag = attribValue;
                }
            }
            else if (current.DataType == AttributeDataType.Boolean)
            {
                m_cbxValue.Items.Add("true");
                m_cbxValue.Items.Add("false");
            }
            m_dgvValues.Sort(m_dgvValues.Columns[0], ListSortDirection.Ascending);
        }