Tag: .net 2.0

(DataGridView + Binding)如何根据绑定的对象来着色线?

我想根据绑定对象的属性为特定行添加背景颜色。 我拥有的解决方案(它的工作原理)是使用Event DataBindingComplete但我不认为这是最好的解决方案。 这是事件: private void myGrid_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { for (int i = 0; i < this.myGrid.Rows.Count; i++) { if((this.myGrid.Rows[i].DataBoundItem as MyObject).Special) { this.myGrid.Rows[i].DefaultCellStyle.BackColor = Color.FromArgb(240, 128, 128); } } } 还有其他更好的选择吗?

将DataTable作为参数发送到存储过程

我正在尝试使用c#,。net 2.0和SQLServer 2012 Express将DataTable发送到存储过程。 这大致就是我正在做的事情: //define the DataTable var accountIdTable = new DataTable(“[dbo].[TypeAccountIdTable]”); //define the column var dataColumn = new DataColumn {ColumnName = “[ID]”, DataType = typeof (Guid)}; //add column to dataTable accountIdTable.Columns.Add(dataColumn); //feed it with the unique contact ids foreach (var uniqueId in uniqueIds) { accountIdTable.Rows.Add(uniqueId); } using (var sqlCmd = new SqlCommand()) { […]

获取对象类型并相应地分配值

我有一个arraylist,它在其中获得不同类型的值 ,第一个值 – > 字符串 ,第二个值 – > datetime ,第三个值 – > 布尔值和第四个值是int ,我如何找到它们的类型并相应地分配这些值,任何感谢帮助:) 这是我的代码: foreach (object obj in lstTop) { if(obj.GetType() == string) {do this…) else if(obj.GetType() == DateTime) {do this….} else if(obj.GetType() == bool) {do this….} else if(obj.GetType() == Int) {do this….} } 谢谢大家, 我的最终守则: string Subscription = “”; DateTime issueFirst; DateTime issueEnd; […]

如何查询一个域的用户是否是另一个AD域中的组的成员?

我有一系列应用程序都使用我创建的相同C#,。Net 2.0代码来检查并查看用户是否是Active Directory组的成员。 直到最近,当我将另一个受信任的AD域中的用户添加到我的一个AD组时,我的代码没有遇到任何问题。 我的问题是如何检查用户是否是Active Directory组的成员,无论他们的域名是谁。 换句话说,它们可能与我的组在同一个域中,也可能不在同一个域中。 下面是我编写并使用多年来搜索以查看用户是否在Active Directory组中的代码。 我不确定我在哪里修改了这段代码,但我认为它来自MSDN文章。 此外,解决方案必须是.Net 2.0框架。 我找到了很多可能适用于.Net 3.5中此问题的答案。 不幸的是,这对我的方案不起作用。 //This method takes a user name and the name of an AD Group (role). //Current implementations of this method do not contain the user’s domain //with userName, because it comes from the Environment.UserName property. private static bool IsInRole(string userName, string […]

如何避免堆栈溢出?

我使用CSharpCodeProvider编译我的代码,并在结果汇编中动态创建某个类的实例。 比我叫一些方法。 如果方法有递归,我得到StackOverflowException,我的应用程序终止。 我该如何避免这种情况? using System; using System.Runtime.Remoting; namespace TestStackOverflow { class Program { class StackOver : MarshalByRefObject { public void Run() { Run(); } } static void Main(string[] args) { AppDomain domain = AppDomain.CreateDomain(“new”); ObjectHandle handle = domain.CreateInstance(typeof (StackOver).Assembly.FullName, typeof (StackOver).FullName); if (handle != null) { StackOver stack = (StackOver) handle.Unwrap(); stack.Run(); } } […]

如何将rtf字符串提供给richtextbox控件

我有一串richtext字符/标记,我想在代码中提供给richtextbox。 string rt = @” {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}{\f1\fnil\fprq2\fcharset0 Biondi;}}”+ @”{\colortbl ;\red255\green0\blue0;}”+ @”{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\f0\fs20\par”+ @”\cf1\f1 hello\cf0\f0 \ul world\par}”; 我试过这个: System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] b = Encoding.ASCII.GetBytes(rt); strm.BeginRead(b, 0, b.Length, null, null); richTextBox1.LoadFile(strm, RichTextBoxStreamType.RichText); 它不起作用。 任何人都可以给我几个sugestions。 BTW富文本来自于从wordpad保存,用记事本打开文件,并使用in来构建我的字符串

如何使用XmlSerializer反序列化为现有实例?

是否有可能使用XmlSerializer将其数据反序列化为现有的类实例而不是新的实例? 这在两种情况下会有所帮助: 轻松将两个XML文件合并到一个对象实例中。 让object constructer本身就是从XML文件加载数据的人。 如果默认情况下不可能,它应该使用reflection(在反序列化后复制每个属性),但这将是一个丑陋的解决方案。

2 DateTime之间的确切时间?

我想知道2个日期之间的很多分钟? 示例:现在 – 确切时间的tommorow将返回1440。

以编程方式最大化窗口并防止用户更改窗口状态

如何以编程方式最大化窗口,使其在达到最大化状态后无法resize(例如,最大化Internet Explorer并查看它)? 我将FormWindowState属性设置为 this.WindowState = FormWindowState.Maximized; this.MaximizedBounds = (x,y); 但它不起作用。 我该怎么做呢? 我想要最大化的窗口是我的应用程序中的一个窗口。

表格在C#中失去了焦点

这可能是一个简单的C#问题,但我需要一个解决方案。 我有两个表单, form1和form2 , form1有一个按钮 。 单击按钮,我想显示form2 。 当form2失去焦点时我想隐藏它( form2 )。 我怎样才能做到这一点? 我试图订阅form2的LostFocus事件,但它无法正常工作。 请帮我解决一下这个。 注意 – 我使用.Net 2.0