我有datagridview
我的C#程序
当我向左移动滚动条时,我想要2个右列
将冻结,不要移动.
怎么做?
很抱歉发布这样的一般性问题,但是对于多种情况可能有多个答案(我可能需要在得到答案之前重新创建数据库),所以这里是:
我们有一个使用EF6的C#项目,已成功使用EF Migrations数月.今天早上,当我尝试运行我的项目时,我得到了这个非常熟悉的错误:
System.Data.Entity.Migrations.Infrastructure.AutomaticMigrationsDisabledException'发生在EntityFramework.dll中但未在用户代码中处理
附加信息:无法更新数据库以匹配当前模型,因为存在挂起的更改并且已禁用自动迁移.将挂起的模型更改写入基于代码的迁移或启用自动迁移.将DbMigrationsConfiguration.AutomaticMigrationsEnabled设置为true以启用自动迁移.
除了我找不到任何改变的证据.
有关这种情况如何发生的任何想法?
我使用 Automapper 将 object 映射source
到 object destination
。有什么方法可以映射,只有具有非默认值的属性,从source
对象到destination
对象?
该DoSomething()
方法会导致内存泄漏吗?
public static class AppContext
{
public static int ApplicationStateId {get; set}
...
}
public class MyService
{
public void DoSomething()
{
....
if(AppContext.ApplicationStateId == 1)
{
//do something
}
}
}
Run Code Online (Sandbox Code Playgroud)
var service = new MyService();
service.DoSomething();
Run Code Online (Sandbox Code Playgroud)
这意味着静态变量及其引用的所有内容永远不会被垃圾收集。
Michael在 .NET 中导致内存泄漏的 8 种方法中说道。
在我的Windows应用程序中,我有一个带网格的上下文菜单,问题是我想根据用户previlages在上下文菜单中禁用ToolStripMenuItem.我怎么能这样做.我这样做了但是没有用
private void contextMenuStrip_Machine_Opening(object sender, CancelEventArgs e)
{
toolStripAuthorize.Enabled = INFOpermission.accessAuthorize;
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用
我有一个List包含接口项IGrid
(我创建了它)
public interface IGrid
{
RowIndex { get; set; }
ColumnIndex { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个方法将List分成多个列表List>
基于RowIndex属性
所以我写道:
public List<List<IGrid>> Separat(List<IGrid> source)
{
List<List<IGrid>> grid = new List<List<IGrid>>();
int max= source.Max(c => c.RowIndex);
int min = source.Min(c => c.RowIndex);
for (int i = min; i <= max; i++)
{
var item = source.Where(c => c.RowIndex == i).ToList();
if (item.Count > 0)
grid.Add(item);
}
return grid;
}
}
Run Code Online (Sandbox Code Playgroud)
有什么更好的方法呢?
我正在开发一个通用搜索表单,该表单中的搜索控件取决于<T>
属性的类型,例如,如果是Order
,
public class Order
{
public string OrderNumber {get; set;} // search control is 1 TextBox
public decimal OrderWeight {get; set;} // search controls are 2 TextBox (for accepting a range)
}
Run Code Online (Sandbox Code Playgroud)
搜索表单将是这样的
我在表单中使用这些语句来确定每个T
属性的适当控件:
if (propertyType.Name == "System.String")
InsertOneTextBox(paramInfo);
else
if(propertyType.Name == "System.Int32" || propertyType.Name == "System.Decimal")
InsertTwoTextBoxs(paramInfo);
else
if(propertyType.Name == "System.DateTime")
InsertTwoDateTimePickers(paramInfo);
else
if(propertyType.Name == someotherconditions)
InsertOneComboBox(paramInfo);
....
Run Code Online (Sandbox Code Playgroud)
是否有任何最佳做法可以避免使用if
else
s或switch
case
决定为每种属性类型设置适当的控件?
SRP负责人说:
一个类或模块应该只有一个改变的理由
我有一些Facade
类作为我的服务层类.例如SaleService
,它提供了一些方法,例如SaveOrder()
,CancelOrder()
,CreateOrder()
,GetAllOrders()
,GetAllPlannedOrders()
,...
我只是因为他们的概念关系而把它们放在一起.
使用这种方法的类可能有多个改变()的原因,违反了SRP吗?如果是的话,我该如何处理这个问题呢?
design-patterns single-responsibility-principle facade conceptual service-layer
我有一个需求,我需要动态地将图像和文本添加到同一列。我已经遵循了很多例子,但没有一个是有效的。也参考以下内容,但在参考上述文章时出现转换错误。无法将类型的对象强制转换System.Windows.Forms.DataGridViewImageCell
为类型DataGridViewCustom.TextAndImageCell
。
有人可以帮忙吗?
我们在winforms应用程序中使用了大量的数据绑定,最近我们遇到了一些难以调试的场景.
在我们的BindingSource上调用ResumeBinding()时,我们收到一个异常:
ex.Type FormatException ex.Message无法将值格式化为所需类型:
在System.Windows.Forms.Binding.FormatObject(对象的值)在System.Windows.Forms.Binding.PullData(布尔重新格式化,布尔力)在System.Windows.Forms.BindingManagerBase.PullData(布尔&成功)在System.Windows. Forms.CurrencyManager.CurrencyManager_PullData()在System.Windows.Forms.CurrencyManager.EndCurrentEdit()在System.Windows.Forms.CurrencyManager.ChangeRecordState(的Int32在newPosition,布尔验证,布尔endCurrentEdit,布尔firePositionChange,布尔pullData)在System.Windows. Forms.CurrencyManager.UpdateIsBinding(布尔raiseItemChangedEvent)在System.Windows.Forms.CurrencyManager.UpdateIsBinding()在System.Windows.Forms.CurrencyManager.ResumeBinding()在System.Windows.Forms.BindingSource.ResumeBinding()在SomeProject.SomePanel. C:\ SomeDir\SomePanel.cs中的FlightData_DataReady():第94行
我们使用的是具有一些Nullable属性的简单对象模型.然而,并非所有人都试图捕捉塞特尔人/吸气者
我们正在使用DevExpress组件,在将属性更改为Nullable属性并将NullText属性添加到DevExpress文本框之后,会启动此特殊异常.
任何人都可以了解如何调试这种情况?
在解决了这个问题后,我注意到一些细节造成了这个问题.
其中一个Nullable双属性被绑定到具有Single属性的控件.数据绑定引擎抛出了一些关于无法将Nullable double转换为Single的第一个更改异常.
调试这个并找出哪个控件/属性应该被责备仍然是不可能的,任何人都有一些线索如何做到这一点?
我正在使用 Windows 窗体应用程序在 C# 中编写一个简单的侧滚器。我希望这样当玩家触摸退出点时,这会立即加载一个新关卡。
为了实现这一点,我使用以下代码:
if (player.Bounds.IntersectsWith(exit.Bounds))
{
Form2 myNewForm = new Form2();
myNewForm.Visible = true;
this.Hide();
}
Run Code Online (Sandbox Code Playgroud)
这有效。但是,它加载了许多 form2 实例 - 我只希望它加载一次。我不知道如何写这个(对不起,我是一个新手 - 我花了一段时间才写这段代码!)。
此外,通过新表单加载关卡效率低下。有没有办法卸载打开的表单以在同一窗口/实例中加载下一个,而不是创建另一个单独的窗口?
对不起,如果这不清楚。我已经做了最好的研究+我是新来的。请不要提及XNA!谢谢。
c# ×8
winforms ×4
.net ×2
automapper ×1
conceptual ×1
data-binding ×1
datagridview ×1
devexpress ×1
exception ×1
facade ×1
generics ×1
hide ×1
if-statement ×1
mapping ×1
memory-leaks ×1
poco ×1
show ×1
single-responsibility-principle ×1
static ×1
toolstrip ×1