小编Hen*_*man的帖子

向单元格赋值时,DataGridView SLOW

我似乎无法弄清楚这里发生了什么...我有一个dataGridView,在任何给定时间不超过500行,但通常大约200或300.我遍历网格并根据用户交互设置按钮文本和颜色.例:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        DataGridViewButtonColumn btn;
        ContextMenuStrip ctxtStartStop;

        public Form1()
        {
            InitializeComponent();

            formatGrid();
            populateGrid();

            ctxtStartStop = new ContextMenuStrip();
            ctxtStartStop.Items.Add("START ALL");
            ctxtStartStop.Items.Add("STOP ALL");
            ctxtStartStop.ItemClicked += new ToolStripItemClickedEventHandler(ctxtMenuStrip_ItemClicked);
        }

        private void formatGrid()
        {
            btn = new DataGridViewButtonColumn();
            btn.Text = "START";
            btn.Name = "colStartStop";
            btn.HeaderText = "Start/Stop";
            btn.DefaultCellStyle.BackColor = Color.LightGreen;
            btn.DefaultCellStyle.ForeColor = Color.Black;
            btn.ReadOnly = false;
            btn.UseColumnTextForButtonValue = false;
            btn.FlatStyle …
Run Code Online (Sandbox Code Playgroud)

c# datagridview winforms

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

C#编译器是否设置了版本或平台常量?

C#编译器中是否有任何预定义的常量来检测所针对的平台版本?

我可以在Project选项中设置一个平台但是如何编写.NET 2和.NET 3.5的单一源代码?

编辑:我真的想编写一些代码,并能够使用#if CLR_VERSION35之类的东西切换行为,然后再进行不同的配置.

相反的问题:如果我制作CLR35和CLR20配置是否可以基于此选择目标平台?该选项在VS2008中不可用,我对MSBUILD还不是很了解.

.net c# compiler-version

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

进度条C#

我有一个进度条来显示将歌曲加载到库中的程序的状态.

    foreach (Song s in InitializeLibrary())
    {
        Library.AddSong(s);
        pBar.Value++;
        pBar.Update();
    }
Run Code Online (Sandbox Code Playgroud)

InitializeLibrary()只是一个返回List的函数

问题是进度条在某个点(例如20%)之后停止"移动",而值仍然增加.有没有办法让它100%更新?

c# winforms progress-bar

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

StreamReader,C#,偷看

我有一个StreamReader,偶尔会检查是否有更多要从简单的文本文件中读取.它使用peek属性.问题在于,当我使用peek时,位置会发生变化,而不是假设.

FileStream m_fsReader = new FileStream(
                        m_strDataFileName,
                        FileMode.OpenOrCreate,
                        FileAccess.Read,
                        FileShare.ReadWrite                        );

StreamReader m_SR = new StreamReader(m_fsReader);

Console.WriteLine("IfCanRead SR Position " + m_fsReader.Position +
     " and Length " + m_fsReader.Length);

if (m_SR.Peek() == -1) {
       Console.WriteLine("IfCanRead false 2 SR Position " + 
             m_fsReader.Position  + " and Length " + m_fsReader.Length);

       return false;
}
else {
       Console.WriteLine("IfCanRead true 2 SR Position " + 
           m_fsReader.Position + " and Length " + m_fsReader.Length);

       return true;
}  
Run Code Online (Sandbox Code Playgroud)

.net c# streamreader peek

2
推荐指数
2
解决办法
5346
查看次数

c#搜索arraylist

在我的代码中,我有一个名为array的arraylist.

我已经填写了1到13的数字

for(int i =1; i< 14; i++)
{
  array.items.Add(i)
}
Run Code Online (Sandbox Code Playgroud)

稍后在我的代码中我也随机删除了一些元素.示例array.remove(3);

现在我想搜索一下,arraylist中元素的多少值超过了特定的数字.

那么,arraylist中有多少元素结束了例如5.

谁知道怎么做?

谢谢!

c#

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

如何避免手动启动的线程死亡?

我在一个在IIS上运行的系统上有一个进程,它需要几个小时才能完成,因此它在一个线程上运行.

问题是这个线程在一段时间后被删除,因为IIS进程超时(没有活动).这个线程不能在中间停止.

如果线程正在运行,如何防止此超时?

c# iis multithreading timeout

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

使用linq将逗号分隔的列表放入列中

我有两个表,它们之间有一对多的关系,并希望执行一个linq查询,该查询将从多个表中获取值,并从连接到每个记录的值中生成一个逗号分隔的列表.其他表.我可以使用"stuff"函数和"for xml path"函数在sql中执行此查询.例如,假设我有以下表结构:

1)区
列:id,名称
2)存储
列:id,name,districtid

现在假设我想生成一个查询以返回以下列:district.id,district.name,stores(与该区域关联的以逗号分隔的商店列表)

如何通过linq实现这一目标?

在一个查询中,我想在没有任何for循环的情况下执行此操作.

c# linq asp.net linq-to-sql

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

在运行时更改表达式委托主体?

我有这个代码生成一个委托,它将myNumber乘以5

ParameterExpression numParam = Expression.Parameter(typeof(int), "num");
ConstantExpression five = Expression.Constant(5, typeof(int));
BinaryExpression numMultiply = Expression.Multiply(numParam,five);
Run Code Online (Sandbox Code Playgroud)

让我们创建委托:

Expression<Func<int, int>> lambda1 =
    Expression.Lambda<Func<int, int>>(
        numMultiply,
        new ParameterExpression[] { numParam });
Console.Write(lambda1.Compile()(4));
Run Code Online (Sandbox Code Playgroud)

现在让我们说我要更改此表达式树Add而不是Multiply
这里是新行:

BinaryExpression numAdd = Expression.Add(numParam,five);
Run Code Online (Sandbox Code Playgroud)

但是我如何更改lambda1以便它现在将使用numAdd而不是multiply

.net c# .net-4.0 expression-trees

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

C#解码"â"¢"到"TM"

在网页上有以下字符串

"Qualcomm Snapdragon™S4"

当我在我的.net代码中得到这个字符串时,字符串转换为"QualcommSnapdragonâ"¢S4"

字符"TM"变为¢

我怎么能解码"â"¢"回到"TM"

更新

follwoing
是使用webproxy下载字符串的代码wc是webproxy

wc.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8");
string html = Server.HtmlEncode(wc.DownloadString(url));
Run Code Online (Sandbox Code Playgroud)

c# encoding decoding

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

为什么我的异步程序抛出 NullReferenceException

我收到以下异常:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at GoogleProducts.Program.<Main>d__0.MoveNext() in C:\Code\test\GoogleProducts\Program.cs:line 60 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at GoogleProducts.Program.<Main>(String[] args)

来源是:

private static async Task Main(string[] args)
        {
            var queries = new[]
            {
                "seico watch",
                "citizen watch",
                "orient watch",
                "bulova watch",
                "seagull watch",
                "glashuette watch"
            };

            var client = new WebClient();

            foreach (var query in queries)
            {
                var url = …
Run Code Online (Sandbox Code Playgroud)

c# task async-await

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