答案 0 :(得分:1)
我建议处理CellFormatting
网格事件并获取太长的值的子字符串:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.Value == null)
return;
if (e.RowIndex < 0)
return;
// only for 2nd column
if (e.ColumnIndex != 1)
return;
var txt = e.Value.ToString();
if (txt.Length > 4608)
{
e.Value = txt.Substring(0, 4608);
e.FormattingApplied = true;
}
}
答案 1 :(得分:1)
如果DataGridViewCell的长度大于4608
,则不会显示该内容
这肯定不是真的,你可能会看到:
using System;
using System.Linq;
using System.Windows.Forms;
namespace Samples
{
static class Test
{
class Foo
{
public int Length { get { return Text != null ? Text.Length : 0; } }
public string Text { get; set; }
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var dataSet = Enumerable.Range(1, 10000).Select(n => new Foo { Text = new string('A', n) }).ToList();
var form = new Form();
var dg = new DataGridView { Dock = DockStyle.Fill, Parent = form };
dg.DataSource = dataSet;
Application.Run(form);
}
}
}
所以代码中一定有问题。