小编YOh*_*han的帖子

以编程方式将单元格和行添加到DataGridView

我正在努力DataGridViewComboBoxCell.在某些情况下(比方说,事件)我必须ComboBox在我的表格中预先选择一个值DataGridView.当用户更改一个框时,我可以以编程方式更改另一个框:

var item = ItemName.Items.GetListItem(name);
if (item != null)
{
    _loading = true; // that's needed to come around another CellValueChanged events
    itemView.Rows[e.RowIndex].Cells["ItemName"].Value = item;
    _loading = false;
}
Run Code Online (Sandbox Code Playgroud)

我这样填充ItemName.Items:

foreach (var item in _model.DefaultData.ItemList)
{
    if (item.Value.Code.HasValue()) ItemCode.Items.Add(new ListItem(item.Key, item.Value.Code));
    ItemName.Items.Add(new ListItem(item.Key, item.Value.Name));
}
Run Code Online (Sandbox Code Playgroud)

GetListItem方法:

public static ListItem GetListItem(this DataGridViewComboBoxCell.ObjectCollection col, string name)
{
    ListItem retItem = null;
    foreach (ListItem item in col)
    {
        if (item.Name == name) { retItem = …
Run Code Online (Sandbox Code Playgroud)

c# datagridview datagridviewcombobox winforms datagridviewcomboboxcell

6
推荐指数
1
解决办法
2万
查看次数

实体框架:跳过/获取功能

我只是好奇Skip和Take函数如何在Entity Framework中工作(使用EF 6.1).

如果我做:

db.Events.OrderByDescending(x => x.Date).Take(maxPageSize).ToList();
Run Code Online (Sandbox Code Playgroud)

我得到一些清单(注意到一个事件已经完全消失).

如果我做:

db.Events.OrderByDescending(x => x.Date).Skip(0).Take(maxPageSize).ToList();
Run Code Online (Sandbox Code Playgroud)

我得到另一个列表,并且此处存在先前查询中的已事件.

任何人都知道我为什么要采取Skip() ZERO实体以便Take()采取我应该采取的措施?它几乎没有任何意义(至少对我而言)......

PS我无法使用SQL Server Profiler来检查生成的查询.

c# entity-framework

5
推荐指数
1
解决办法
5016
查看次数

参考类型中的C#HasValue

是否可以Nullable<>.HasValue在引用类型上使用?

假设我们从值类型中得到了这个例子:

int? a = GetNullOrValue(); // completely randomly gets random number or null
if (a.HasValue) return 0;
Run Code Online (Sandbox Code Playgroud)

我想要完成的是:

class Foo 
{
    public string Bar { get; set; }
}

Foo foo = GetNullOrFoo(); // completely randomly gets Foo ref. or null

if (foo.HasValue) return foo.Bar; // of course this will throw NullReferenceException if foo is null
Run Code Online (Sandbox Code Playgroud)

我希望实现这一点以获得更好的可读性,因为我更喜欢"单词内容",而不是"符号内容"(x.HasValue而不是x != null).

c# nullable reference reference-type

1
推荐指数
1
解决办法
576
查看次数