Пример #1
0
        private void btnEditChannel_Click(object sender, EventArgs e)
        {
            if (lvChannels.SelectedItems.Count == 1)
            {
                using (var form = new FormRadioChannel(mf))
                {
                    var selectedChannel = (CRadioChannel)lvChannels.SelectedItems[0].Tag;

                    form.Channel.Id        = selectedChannel.Id;
                    form.Channel.Name      = selectedChannel.Name;
                    form.Channel.Frequency = selectedChannel.Frequency;
                    form.Channel.Location  = selectedChannel.Location;

                    if (form.ShowDialog(this) == DialogResult.OK)
                    {
                        // Set in channel
                        selectedChannel.Id        = form.Channel.Id;
                        selectedChannel.Name      = form.Channel.Name;
                        selectedChannel.Frequency = form.Channel.Frequency;
                        selectedChannel.Location  = form.Channel.Location;

                        // Set in listview
                        // TODO: Use keys
                        lvChannels.SelectedItems[0].SubItems[0].Text = selectedChannel.Id.ToString();
                        lvChannels.SelectedItems[0].SubItems[1].Text = selectedChannel.Name;
                        lvChannels.SelectedItems[0].SubItems[2].Text = selectedChannel.Frequency;

                        // Resize
                        lvChannels.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                        lvChannels.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent);
                    }
                }
            }
        }
Пример #2
0
        private void btnAddChannel_Click(object sender, EventArgs e)
        {
            using (var form = new FormRadioChannel(mf))
            {
                // Get max id
                var maxChannelId = 0;

                if (_channels.Count > 0)
                {
                    maxChannelId = _channels.Max(c => c.Id);
                }

                form.Channel.Id = maxChannelId + 1;

                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    _channels.Add(form.Channel);
                    AddChannelToListView(form.Channel);

                    // Resize
                    lvChannels.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                    lvChannels.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent);
                }
            }
        }