小编spa*_*jce的帖子

"BindingSource不能是它自己的数据源" - 尝试从另一个类中的方法重置绑定源时出错

我们绑定一个DataGridview使用BindingSource.所以在我们这样给出的主线程中.

            class1BindingSource = new BindingSource();
            class1BindingSource.DataSource = class1List;  
            this.dataGridView1.DataSource = class1BindingSource;
Run Code Online (Sandbox Code Playgroud)

之后,我在窗体中放置了一个后台工作器,并在单击按钮时触发.

即在按钮单击中

this.backgroundWorker1.RunWorkerAsync()
Run Code Online (Sandbox Code Playgroud)

BackgroundWorker DoWork Event我试图BindingSource通过尝试更新来更新和那里DataGridview.

因此,BindingSource重置是在另一个类的方法中完成的.

DoWork Event

Class2 cl2 = new Class2();
cl2.UpdateBindingSource(class1BindingSource);
Run Code Online (Sandbox Code Playgroud)

UpdateBindingSource Method

public void UpdateBindingSource(BindingSource bs)
        {
            Class1 c1 = bs.Current as Class1;    
            for (int i = 0; i < 1000; i++)
            {
                lock (bs.SyncRoot)
                {
                    c1.MyProperty1 = i;
                    bs.ResetItem(0);
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

现在我得到一个例外,就像BindingSource它不能成为自己的数据源一样.不要将DataSourceDataMember属性设置为引用的值BindingSource. …

datagridview backgroundworker thread-safety bindingsource winforms

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

授权角色和权限

我正在使用ServiceStack并已开始为我的服务添加基于角色的授权.从文档中我可以看到有服务通过Web服务从用户分配和删除角色.

我的问题是ServiceStack中是否包含任何内置服务来查询用户当前拥有的角色和权限?

c# authorization servicestack

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

将列表框的项目保存到文本文件

如何listbox使用SaveFileDialog?将项目的内容保存到文本文件?

我还想在文本文件中添加其他信息,并添加MessageBox成功后保存的说法.

c# listbox text-files

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

Lidgren网络,无法让它连接

我无法让我的客户端在我的lindgren网络测试中连接到我的服务器.我尝试了多种连接方式,但是当我尝试连接时它总是停止.对不起,如果这是一个广泛的问题,但我做错了什么?这是我的代码:

class Program
{
    static NetPeerConfiguration serverconfig;
    static NetPeerConfiguration clientconfig;
    static NetServer server;
    static NetClient client;

    static void Main()
    {
        Console.Title = "LidgrenNetworkTest";
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine("LidgrenNetworkTest console initialized.");
        Console.ForegroundColor = ConsoleColor.Gray;
        Console.Write("Color codes: ");
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.Write("System ");
        Console.ForegroundColor = ConsoleColor.Gray;
        Console.Write("Input ");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write("Sent ");
        Console.ForegroundColor = ConsoleColor.Cyan;
        Console.Write("Received");
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine("\n");

        Console.WriteLine("Configuring server...");
        serverconfig = new NetPeerConfiguration("LidgrenNetworkTest");
        serverconfig.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
        serverconfig.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
        serverconfig.LocalAddress = NetUtility.Resolve("localhost");
        serverconfig.Port = 8080;
        Console.WriteLine("Server configured.");

        Console.WriteLine("Configuring client...");
        clientconfig = new NetPeerConfiguration("LidgrenNetworkTest"); …
Run Code Online (Sandbox Code Playgroud)

c# networking

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

访问检索到的数据

我一直试图找到这个问题的答案好几天,我发现很难相信这不可能做到.

我想要在DataSet/DataTable构建页面时SqlDataSource.SelectASP.NET运行时自动调用方法时构建.

我知道我可以在代码后面运行它,但这使得第二次访问数据库,我真的想避免这种情况.我遇到的每个例子都告诉你在后面的代码中执行Select方法.

有没有办法访问已经检索的数据?

c# asp.net ado.net sqldatasource

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

发布数据JQuery UI Tabs 1.10

我刚刚从JQ UI 1.8.23切换到1.10.至于这个版本,ajaxOptions不推荐使用,现在ui.ajaxSettings改为使用.

这就是我的代码的样子:

$( "#tabs" ).tabs({
        ajaxOptions: {
            type : 'POST',
            data : 'format=html',
            error: function( xhr, status, index, anchor ) {
                $( anchor.hash ).html(
                    "Couldn't load this tab. We'll try to fix this as soon as possible. " +
                    "If this wouldn't be a demo. " );
            },
            success: function() { 
                *Something in here*
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

一切都很好.现在新代码:

$( "#tabs" ).tabs({
         beforeLoad: function( event, ui ) {
             ui.ajaxSettings.type = 'POST'; …
Run Code Online (Sandbox Code Playgroud)

jquery post zend-framework jquery-ui

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

获取datagridview的总和使用Linq获取不同ID的列

我有两种形式,Form1(DGV1 & DGV2)并且两种形式Form2(DGV3 & DGV4)都有Datagridview控件.

Form1那里有一个Form2用户可以添加行的按钮链接Form1 datagridview(DGV1).在Form2 ? (DGV3 and DGV4),checkbox第一列中有一个,用户一次只能选择一行.

有两个按钮Form2:DoneAdd Items

当用户通过一个接一个地选择行来单击"添加项目"时,必须将行添加到" datagridview打开" Form1,单击"完成"按钮时,Form1应显示添加的所有行.

我做到了这一点.

列中的DGV1DGV2

DGV1色谱柱

Sno Desciption SellQty ItemID
----------------------------
 1    ABC       0         1 
 2    XYZ       0         2
Run Code Online (Sandbox Code Playgroud)

DGV2色谱柱

Sno BatchNo SellQty ItemID
----------------------------
1    123       10         1
2    528       20         2
1    568       30         1
2 …
Run Code Online (Sandbox Code Playgroud)

c# datagridview winforms

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

验证我的表格

我是新手.Net Framework,我想在我的Windows窗体应用程序中添加验证Visual Studio 2010 IDE.我已经搜索了不同的方法,但我不确定在哪里可以添加我的表单中的代码?其中一个例子是下面的代码.

我是否在表单加载方法或提交按钮或其他位置添加此代码?

using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;

namespace MvcMovie.Models
{
    public class Movie
    {
        public int ID { get; set; }

        [Required(ErrorMessage = "Title is required")]
        public string Title { get; set; }

        [Required(ErrorMessage = "Date is required")]
        public DateTime ReleaseDate { get; set; }

        [Required(ErrorMessage = "Genre must be specified")]
        public string Genre { get; set; }

        [Required(ErrorMessage = "Price Required")]
        [Range(1, 100, ErrorMessage = "Price must be between $1 …
Run Code Online (Sandbox Code Playgroud)

.net c# textbox winforms

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

打印文档

我想打印我的TextBox,这是我的代码:

private void MenuItemPrint()
{
        if (FileName != "")
        {
            PrintDocument document = new PrintDocument();
            document.PrinterSettings.PrintFileName = FileName;
            document.Print();
        }
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用。我应该怎么办?

c# printing

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

如何使用按组数据创建左连接

我有三个表一是" Allowance"," Balance"和" TimeoffRequests"在这三个表中的公共列是EmployeeIdTimeoffTypeId,现在我需要通过分组他们timeoffTypeIdEmployeeId表" TimeoffRequests"得到一个请假的一个请求时间,并得到" TimeOffHours" .因为我写的代码就像

var query = (from tr in TimeOffRequests
             where tr.EmployeeID == 9
             group tr by new { tr.EmployeeID, tr.TimeOffTypeID } into res
             select new
             {
                 EmployeeID = res.Key.EmployeeID,
                 TimeOffTypeID = res.Key.TimeOffTypeID,
                 TotalHours = res.Sum(x => x.TimeOffHours)
             }).AsEnumerable();
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

现在我需要将这些结果与第一个表联系起来,并且必须从所有员工中获取,并timeoffTypes从分组表中的UserAllowance相应TimeoffHours表中获取.为了得到左连接查询我写如下.

var requestResult = (from UA in UserAllowances
                     join UB in UserBalances on UA.EmployeeID equals UB.EmployeeID
                     where UA.TimeOffTypeID …
Run Code Online (Sandbox Code Playgroud)

c# linq left-join

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