コード例 #1
0
        private void TbxKeyTextChanged(object sender, EventArgs e)
        {
            if (m_trvTables.SelectedNode == null || m_trvTables.SelectedNode.Tag == null)
            {
                return;
            }
            var    rbfv = (AttributeValue)m_trvTables.SelectedNode.Tag;
            var    x    = (TextBox)sender;
            string old  = rbfv.Key;

            rbfv.Key = x.Text;
            if (old != rbfv.Key)
            {
                if (HasChangesChanged != null)
                {
                    HasChangesChanged(this, true);
                }
            }

            m_cbxValue.Items.Clear();
            if (!FillComboBoxByUserPath(m_cbxValue.Items, m_tbxKey.Text))
            {
                m_cbxValue.Items.AddRange(RBFDictionary.GetDictEntries(m_tbxKey.Text));
            }
        }
コード例 #2
0
        private void DgvValuesCellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex < 0)
            {
                return;
            }
            DataGridViewRow  row  = m_dgvValues.Rows[e.RowIndex];
            DataGridViewCell cell = row.Cells[e.ColumnIndex];
            var attribValue       = (AttributeValue)row.Tag;

            if (attribValue == null)
            {
                return;
            }
            // key
            if (e.ColumnIndex == 0)
            {
                if (HasChangesChanged != null)
                {
                    HasChangesChanged(this, true);
                }
                attribValue.Key = cell.Value.ToString();
                if (cell is DataGridViewComboBoxCell)
                {
                    var    combo = row.Cells[1] as DataGridViewComboBoxCell;
                    string value = combo.Value.ToString();
                    for (int i = 0; i < combo.Items.Count; i++)
                    {
                        if (combo.Items[i].ToString() != value)
                        {
                            combo.Items.RemoveAt(i--);
                        }
                    }
                    if (!FillComboBoxByUserPath(combo.Items, cell.Value.ToString()))
                    {
                        combo.Items.AddRange(RBFDictionary.GetDictEntries(cell.Value.ToString()));
                    }
                }
            }
            // value
            else if (e.ColumnIndex == 1)
            {
                if (HasChangesChanged != null)
                {
                    HasChangesChanged(this, true);
                }
                if (cell == null || cell.Value == null)
                {
                    attribValue.Data = AttributeValue.ConvertStringToData(string.Empty, attribValue.DataType);
                    return;
                }
                object oldData = attribValue.Data;
                try
                {
                    attribValue.Data = AttributeValue.ConvertStringToData(cell.Value.ToString(), attribValue.DataType);
                }
                catch (Exception ex)
                {
                    attribValue.Data = oldData;
                    UIHelper.ShowError("Invalid value!");
                }

                if (cell is DataGridViewComboBoxCell)
                {
                    var    combo = cell as DataGridViewComboBoxCell;
                    string value = combo.Value.ToString();
                    for (int i = 0; i < combo.Items.Count; i++)
                    {
                        if (combo.Items[i].ToString() != value)
                        {
                            combo.Items.RemoveAt(i--);
                        }
                    }
                    if (value.Contains('\\'))
                    {
                        string   relativePath = value.SubstringBeforeLast('\\');
                        string[] files        = GetAttribFiles(relativePath);
                        if (files != null)
                        {
                            combo.Items.AddRange(files);
                        }
                        files = GetDataFiles(relativePath);
                        if (files != null)
                        {
                            combo.Items.AddRange(files);
                        }
                    }
                }
            }
            // type
            else if (e.ColumnIndex == 2)
            {
                if (HasChangesChanged != null)
                {
                    HasChangesChanged(this, true);
                }
                attribValue.DataType = AttributeValue.ConvertStringToType(cell.Value.ToString());
            }
        }
コード例 #3
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);
        }