小编Max*_*rdt的帖子

在更改类的名称空间后,无法使用binaryFormatter反序列化

更改我的类的命名空间后,我不能再反序列化对象.我已经实施了SerializationBinder.例:

public class TypeNameConverter : SerializationBinder
{
    public override Type BindToType(string assemblyName, string typeName)
    {
        typeName = typeName.Replace("MyOldNamespace", "MyNewNamespace");
        return Type.GetType(string.Format("{0}, {1}", typeName, assemblyName));
    }
}

BinaryFormatter bf = new BinaryFormatter();
bf.Binder = new TypeNameConverter();
Run Code Online (Sandbox Code Playgroud)

我得到的例外是:

'System.Runtime.Serialization.TypeLoadExceptionHolder'无法转换为'MyNewNamespace.MyClass'类型

c# deserialization

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

用户在运行时调整TableLayoutPanel中行和列的大小

我正在研究WinForm项目,并“尝试”创建一个TableLayoutPanel,用户可以在运行时调整大小,例如SplitContainer的行为。我发现一些代码可以部分执行此操作,但是它不完整。有人可以帮我吗?

在此先感谢-DA

到目前为止,这是我在CodeProject上找到的线程中提供的代码。我自己所做的唯一不同是创建一个从TableLayoutPanel继承的customTableLayoutPanel。

public partial class Form1 : Form
{
    bool resizing = false;
    TableLayoutRowStyleCollection rowStyles;
    TableLayoutColumnStyleCollection columnStyles;

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        rowStyles = tableLayoutPanel1.RowStyles;
        columnStyles = tableLayoutPanel1.ColumnStyles;
    }

    private void tableLayoutPanel1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            resizing = true;
        }
    }

    private void tableLayoutPanel1_MouseMove(object sender, MouseEventArgs e)
    {
        if (resizing)
        {
            columnStyles[0].SizeType = SizeType.Absolute;
            rowStyles[0].SizeType = SizeType.Absolute;
            rowStyles[0].Height = e.Y;
            columnStyles[0].Width = e.X;
        }
    }

    private void …
Run Code Online (Sandbox Code Playgroud)

c# winforms

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

在BindingList中定位对象

我有一个Asynchronous BindingList,它包含在工作线程上操作并绑定到主UI线程上的BindingSource的对象,其中BindingSource绑定到DataGridView.

有没有可能在我的BindingList中找到对象而不迭代列表?

我看过LINQ的引擎盖,它基本上是一个糖涂层的foreach循环.另外从我的理解,如果我实现IBindingList.Find()它只不过是一个for循环...

我已经"尝试"将我的BindingList同步/映射到一个反映我的BindingList的字典,并使用Dictionary来定位对象并将结果(索引)传递给我的BindingList,但这不起作用,因为添加和删除太多了对象和我无法保持井井有条.

这是一款高性能的应用程序,处理来自股票市场的实时高频数据.这就是为什么我不能遍历BindingList,这太低效了.

有人可以给我一些建议和/或解决方案.

c# bindinglist winforms

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

向单元格赋值时,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
查看次数

如何将图像添加到ToolStripMenuItem

我有一个使用ContextMenuStrip的C#winForm项目.我根据使用交互动态地将ToolStripMenuItems添加到ContextMenuStrip.当我添加一个新的ToolStripMenuItem时,我设置了它的Text属性和Image属性.我不知道如何设置Image属性而不从它所在的位置获取图像.如何将想象添加到我的项目中?这是我的代码正在做的一个例子

    ContextMenuStrip cxtMnuStrp = new ContextMenuStrip;

    private void Button_Click(object sender, EventArgs e)
    {
       // some filtering and logic
       // to determine weather to 
       // create and add a ToolStripMenuItem
       // blah, blah, blah...

       ToolStripMenuItem item = new ToolStripMenuItem("uniqueName");

       item.Image = Image.FromFile(@"C:\MyFolder\MyIcon.ico");

       if (cxtMnuStrp.Items.ContainsKey(item) == false)
           cxtMnuStrp.Items.Add(item);
    }

使用"item.Image = Image.FromFile(@"C:\ MyFolder\MyIcon.ico")"当我分发我的每台机器时,必须有"C:\ MyFoler"目录并且还有"MyIcon.ico"在他们的计算机上的"C:\ MyFoler"目录中.

另外,每次我想在ToolStripMenuItem上添加一个图标时,我都点击硬盘驱动器似乎不对

c# winforms

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

如何使用List <T>引用Dictionary值?

我想List<MyObject> myList参考词典myDic值......我试过了

myList = myDic.Values.ToList() 
Run Code Online (Sandbox Code Playgroud)

但这似乎只复制字典值.我需要列表来引用字典,因此对myDic进行的任何修改(添加,删除,更新)都将反映在myList中.

c#

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

如何在MySQL查询中使用OR

我是SQL新手,无法理解为什么这个查询没有返回结果但是我知道这是因为我正在使用OR条件不正确.如果

有人可以请出示正确的方法来解决这个问题吗?

SELECT trddata.id, trddata.ts, instr.name, instr.underlying, instr.expiration,instr.strike, instr.callput,opnint.vol, trdind.name ind,exch.name exch, trddata.price,trddata.bidprcbbo,trddata.askprcbbo  
FROM trdopt trddata 
JOIN instropt instr 
ON trddata.optid = instr.id 
JOIN trdindopt trdind 
ON trdind.id = trddata.ind 
JOIN exchopt exch 
ON trddata.exchcode = exch.id 
JOIN opnintopt opnint 
ON opnint.optid = trddata.optid 
WHERE opnint.ds = DATE_FORMAT(trddata.ts, '%Y-%m-%d') 
AND trddata.id >= 71125752 
AND trddata.ts <= '2013-06-20 16:30:36' 
AND instr.underlying = 'AAPL'  
AND exch.name = 'AMEX'  
OR exch.name = 'CBOE'  
OR exch.name = 'ISE'  
OR exch.name = 'PHLX'  
ORDER BY …
Run Code Online (Sandbox Code Playgroud)

mysql sql

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

标签 统计

c# ×6

winforms ×4

bindinglist ×1

datagridview ×1

deserialization ×1

mysql ×1

sql ×1