我正在尝试将字符串中包含的大约 100-500 个单词的文本显示到数据表单行的两列中,然后将其设置为 DataSource
值 DataGridView
控件。
现在即使它呈现非常缓慢/滚动需要很长时间。
我已经将 DefaultStyleMode
设置为 WordWrap = true
,并调整了行高以显示文本。
是否有任何替代方法可以加快速度,或者我应该研究将 TextBox
添加到 DataGridView
的单元格中?
最佳答案
如何只显示几个字符并使其可点击,这样当用户点击它时,整个文本可以显示在弹出窗口中?
首先,您必须已将原始文本存储在应用程序的某个位置。假设您在数组 string[] texts
您所要做的就是:
- 仅将部分文本添加到
DataGridView
控件而不是整个文本
您可以使用 string
类中的 Split
方法来完成此操作。示例:
string text = "Oscar Mederos";
string portion = text.Substring(0, 3); //portion will be "Osc"
如果需要,您可以在字符串末尾添加 ...
。
- 策划事件
CellClick
的DataGridView
。
在您的应用程序中订阅该事件,并执行如下操作:
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/