我试图在Visual Studio 2008中使我的DataGridView的列标题变粗.
每次我将ColumnHeadersDefaultCellStyle更改为Calibri 9.75pt粗体时,使用属性框,下次重新打开保存的表单时,ColumnHeadersDefaultCellStyle已恢复为Calibri 9.75而不加粗体.
我的表单的字体是Calibri 9.75,没有粗体,我的默认单元格样式,但我应该能够使用我的ColumnHeader样式覆盖默认单元格样式吗?
我可以通过在显示表单时设置样式来以编程方式解决此问题,但我们希望Visual Studio设计器显示粗体标题,因此我们可以针对由粗体标题文本占用的空间适当地布置列.
此外,实际的设计器文件指定ColumnHeadersDefaultCellStyle是粗体,即使设计器界面说它不是粗体.
dataGridViewCellStyle1.Font = new System.Drawing.Font("Calibri", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.receiptDetailView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
Run Code Online (Sandbox Code Playgroud) 我可以在网上找到的每个"依赖"的例子使用"必需"规则.显然这还不够.如何使用"depends"子句,例如"正则表达式"规则?
我有两个单选按钮,如果选中一个,我正则表达式验证文本框.如果选择了另一个,我不关心文本框中的内容.
我有一个node.js服务器应用程序和一个浏览器客户端.发送ArrayBuffer数据浏览器 - >服务器工作正常,但服务器 - >浏览器导致"[object ArrayBuffer]"收到字符串.这种情况发生在Chrome和Firefox的最新版本中.
服务器:
var serverPort = 9867;
// dependencies
var webSocketServer = require('websocket').server;
var http = require('http');
var players = {};
var nextPlayerId = 0;
// create http server
var server = http.createServer(function(request, response) { });
server.listen(serverPort, function() {
console.log((new Date()) + " Server is listening on port " + serverPort);
});
// create websocket server
var wServer = new webSocketServer({ httpServer: server });
// connection request callback
wServer.on('request', function(request) {
var …Run Code Online (Sandbox Code Playgroud) 我有一个DataGrid,用户可以通过在最后一行输入数据来添加项目.我还有一个删除当前所选项目的按钮.但是当选择最后一个(空的,用于添加新项目)行时,最后选择的项目保留在SelectedItem中.因此,如果我打开窗口,选择最后一行,然后按删除按钮,它将删除第一行,因为它是默认选中的,并且选择最后一行不会更改SelectedItem.有什么好方法可以解决这个问题吗?
澄清:SelectedItem ="{Binding X}"
选择最后一行时,ViewModel中的X不会更改(根本不调用setter).我不确定SelectedItem属性本身是否会发生变化,但我认为它不会.
当我选择最后一行(红色边框)时也有一个例外,但当我再次单击它以开始输入数据时,红色边框会消失.不确定这两者是否相关.
我有一个带有一些DataGridViewComboBoxColumns的DataGridView.DataGridView上有一个CellEnter事件处理程序,用于单击下拉组合框.
该列绑定到KeyValuePairs列表,ValueMember为"Key",DisplayMember为"Value".
当我点击组合框列时,它工作正常.但是,如果单元格处于"下拉"状态并且我单击另一个组合框(相同的列,不同的行),它会正确地取消选择旧单元格,选择并下拉新单元格,但是顶部的选定值会更改为在更改回正确的值之前,从旧单元格中获取值一瞬间.
例如,假设列表是A,B,C.在row1中,选择A,在row2中选择B. 我单击row1中的单元格,一切都是应该的.然后,当这个单元格下拉时,我点击第2行中的单元格.它正确地下降,但顶部的选定值变为A,然后立即切换回B(正确的值).
如果在单击第二个组合框单元格之前单击其他列中的单元格,则不会发生这种情况.
有没有办法防止这种情况发生?
重现问题的示例代码(事件处理程序连接到明显的事件):
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 PDGV
{
public partial class Form1 : Form
{
List<KeyValuePair<string, string>> bindingList = new List<KeyValuePair<string, string>>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Rows.Add(10);
bindingList.Add(new KeyValuePair<string,string>("aaa", "111"));
bindingList.Add(new KeyValuePair<string,string>("bbb", "222"));
bindingList.Add(new KeyValuePair<string,string>("ccc", "333"));
bindingList.Add(new KeyValuePair<string,string>("ddd", "444"));
bindingList.Add(new KeyValuePair<string,string>("eee", "555"));
BindComboList(2, bindingList);
}
private void BindComboList(int columnIndex, object list)
{
var …Run Code Online (Sandbox Code Playgroud) 有一个在我们的WinForms托管WPF应用程序内存泄漏FlowDocumentReader的一个ElementHost.我在一个简单的项目中重新创建了这个问题,并添加了下面的代码.
当我按下button1:
UserControl1只包含a的A FlowDocumentReader被创建并设置为ElementHost'sChildFlowDocument是从文本文件创建的(它只包含一个FlowDocument带有StackPanel几千行的文件<TextBox/>)FlowDocumentReader的Document属性设置为这FlowDocument此时,页面呈现FlowDocument正确.正如预期的那样,使用了大量内存.
如果button1再次单击,则内存使用量会增加,并且每次重复该过程时都会不断增加!尽管使用了大量新内存,GC仍未收集!没有参考不应该存在,因为:
如果我按下button2哪个设置elementHost1.Child为null并调用GC(参见下面的代码),则会发生另一个奇怪的事情 - 它不会清理内存,但如果我继续点击它几秒钟,它最终将释放它!
我们所有这些记忆都被使用是不可接受的.此外,ElementHost从Controls集合中删除Disposing它,将引用设置为null,然后调用GC不会释放内存.
button1点击多次,内存使用量不应该继续增加这不是内存使用无关紧要的事情,我可以随时让GC收集它.它实际上最终明显减慢了机器的速度.
如果你只是想下载VS项目,我已经在这里上传了它:http: //speedy.sh/8T5P2/WindowsFormsApplication7.zip
否则,这是相关代码.只需在设计器中为表单添加2个按钮,然后将它们连接到事件即可.Form1.cs中:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using …Run Code Online (Sandbox Code Playgroud) public class MyList : List<MyClass>
Run Code Online (Sandbox Code Playgroud)
MyClass如果我有一个object包含实例的实例,如何通过反射获取类型MyList?列表可以是空的,所以我不能做类似的事情myList[0].GetType().
ps我不能只是停止使用MyList并直接使用通用List(情况有点复杂,并且有"隐藏"泛型参数的原因),所以我无法MyClass通过GetGenericArguments().
我有一个数据网格,其中包含我以编程方式生成的可变数量的列。它包含 DataGridTemplateColumns,每个列都有一个包含 CheckBox 和 TextBlock 的 DockPanel。
绑定代码:
Binding bindingPicked = new Binding(string.Format("Prices[{0}].Picked", i));
bindingPicked.Mode = BindingMode.TwoWay;
Run Code Online (Sandbox Code Playgroud)
复选框代码:
FrameworkElementFactory factoryCheckBox = new FrameworkElementFactory(typeof(CheckBox));
factoryCheckBox.SetValue(CheckBox.IsCheckedProperty, bindingPicked);
Run Code Online (Sandbox Code Playgroud)
所选属性:
private bool _picked;
public bool Picked
{
get { return _picked; }
set { _picked = value; }
}
Run Code Online (Sandbox Code Playgroud)
当数据网格初始化时,将按预期调用 Picked getter。但是,当我选中/取消选中复选框时,不会调用设置器。是什么原因造成的?我不想使用 DependencyProperty,并且我认为不需要它,因为我只需要在用户单击复选框时调用属性设置器。
编辑:显然我是个白痴,我只是忘记了 bindingPicked.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; 请随意关闭它。
我有两个清单.两个列表的类型都继承自相同的基类型.我想迭代它们并执行仅使用基类功能的操作,而不必依次使用两个基本相同的foreach循环.
我无法将列表复制到另一个列表或类似的东西,因为我需要在操作完成后单独使用原始表单中的列表.
有没有办法在不编写函数的情况下执行此操作?
class Program
{
static void Main(string[] args)
{
// I have two lists of inherited classes
List<Babby1> list1 = returnBabby1();
List<Babby2> list2 = returnBabby2();
// I want to iterate through both, and do the same thing, which is a part
// of the base class functionality.
// Basically I want this to be a single foreach loop.
foreach (Babby1 item in list1)
item.var = 50;
foreach (Babby2 item in list2)
item.var = 50;
// I have to …Run Code Online (Sandbox Code Playgroud) c# ×6
wpf ×3
datagridview ×2
winforms ×2
arraybuffer ×1
data-binding ×1
datagrid ×1
elementhost ×1
flowdocument ×1
javascript ×1
jquery ×1
mvvm ×1
node.js ×1
reflection ×1
validation ×1
websocket ×1