コード例 #1
0
        /// <summary>
        /// Checks that all required fiels are filled when the user edits a row
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvNews_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (_ignore)
            {
                return;
            }
            bool           allCellsOK = true;
            var            row        = dgvNews.Rows[e.RowIndex];
            NewsSourceType type       = cbbSourceType.GetSelectedValue <Tuple <string, NewsSourceType> >().Item2;

            foreach (DataGridViewCell c in row.Cells)
            {
                if (/*c.ColumnIndex == colFilter.Index ||*/ c.ColumnIndex == colRemove.Index)
                {
                    continue;
                }
                if (c.ColumnIndex == colURL.Index && type == NewsSourceType.Twitter)
                {
                    continue;
                }
                if (c.Value == null || c.Value.ToString() == string.Empty)
                {
                    allCellsOK  = false;
                    c.ErrorText = "Mandatory";
                }
                else
                {
                    c.ErrorText = string.Empty;
                }
            }
            if (!allCellsOK)
            {
                e.Cancel = true;
            }
        }
コード例 #2
0
        /// <summary>
        /// Populates the list of sources
        /// </summary>
        private void PopulateNewsSourcesList()
        {
            _ignore = true;
            dgvNews.SuspendLayout();
            NewsSourceType type = cbbSourceType.GetSelectedValue <Tuple <string, NewsSourceType> >().Item2;

            colURL.Visible = type == NewsSourceType.RSS;
            if (_dbContext != null)
            {
                _dbContext.SaveChanges();
                _dbContext.Dispose();
            }
            _dbContext = new CoinTNetContext();
            _dbContext.NewsSources.Where(ns => ns.Type == (int)type).Load();
            var newsList = _dbContext.NewsSources.Local.ToBindingList();

            _bindingSource        = new BindingSource(newsList, null);
            _bindingSource.Filter = "Type == 0";
            dgvNews.DataSource    = _bindingSource;
            dgvNews.ResumeLayout();
            _ignore = false;
        }