c# - 在 datagridview 单元格中显示长文本

标签 c# datagridview textbox

我正在尝试将字符串中包含的大约 100-500 个单词的文本显示到数据表单行的两列中,然后将其设置为 DataSourceDataGridView 控件。

现在即使它呈现非常缓慢/滚动需要很长时间。

我已经将 DefaultStyleMode 设置为 WordWrap = true,并调整了行高以显示文本。

是否有任何替代方法可以加快速度,或者我应该研究将 TextBox 添加到 DataGridView 的单元格中?

最佳答案

如何只显示几个字符并使其可点击,这样当用户点击它时,整个文本可以显示在弹出窗口中?

首先,您必须已将原始文本存储在应用程序的某个位置。假设您在数组 string[] texts

中有文本

您所要做的就是:

  • 仅将部分文本添加到 DataGridView 控件而不是整个文本

您可以使用 string 类中的 Split 方法来完成此操作。示例:

string text = "Oscar Mederos";
string portion = text.Substring(0, 3); //portion will be "Osc"

如果需要,您可以在字符串末尾添加 ...

在您的应用程序中订阅该事件,并执行如下操作:

void DataGridView1_OnCellClick(object sender, DataGridViewCellEventArgs e)
{
    int rowClicked = e.RowIndex;
    int columnClicked = e.ColumnIndex;

    ///If the column clicked was the one that has the long texts, 
    //just find the original text in 'texts' using 'rowClicked' and show the 
    //message using MessageBox or creating a new Form for that purpose and 
    //showing it using ShowDialog()
}

关于c# - 在 datagridview 单元格中显示长文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5865661/

相关文章:

c# - 从 Datagridview 更新 MS Access 数据库

php - 将txt文件/数据导入到我的mysql数据库

ASP.net 文本框表现不稳定

c# - 订购 PLINQ ForAll

c# - 绑定(bind)到 BindingList 的 DataGridView 显示太多列

c# - UWP C#中的HtmlAgilityPack Youtube搜索

c# - 垂直滚动条在C#中的DataGridView上不断消失

javascript - 获取/设置 asp :textbox values from javascript

c# - 重新定位到 Windows Phone 8.1

c# - 我是如何搞砸 PLINQ 的? (并行化简单/快速计算)