[英]Change column view DataGridView
The title may be a bit confusing, and I'll try my best in trying to explain my problem. 标题可能会有些混乱,我将尽力解释我的问题。
I have a horizontally scrollable datagridview
and when I click a button on the menu bar, I want the datagridview
to move the view to the specified column, while still having all columns still visible. 我有一个水平滚动的datagridview
,当我单击菜单栏上的一个按钮时,我希望datagridview
将视图移动到指定的列,同时仍然保持所有列可见。
So For example I click on Fish, and then the datagridview
should scroll/position itself to the first mention of Fish in the columns to show a section of the view all related to Fish, while still maintaining all other columns not related to Fish and viewable. 因此,例如,我单击Fish,然后datagridview
应当滚动/定位到列中第一个提及的Fish,以显示视图中与Fish相关的部分,同时仍保持与Fish不相关且可见的所有其他列。
What I would like to know is, is the moving of the position of the view possible to do? 我想知道的是,是否可以移动视图的位置? I didn't know what to search up, and more or less the results of the search included re-ordering of the columns, which I do not want. 我不知道要搜索什么,或多或少的搜索结果包括不希望的列重新排序。
For a DataGridView
with windows form --- give your cell
to Particuler Id . 对于具有Windows 窗体的DataGridView
---将cell
格提供给Particuler Id 。 Like you want to assign a one column
with Fish
then 就像您要为Fish
分配一个column
,然后
row.Cells["Name"].Value = Fish.Id;
and then on click
event
give focus
to this id . 然后在click
event
将focus
该id上 。
Note:- for a better solution post your question with your code
. 注意:- 为了获得更好的解决方案,请在code
张贴您的问题。 thanks 谢谢
Replace fish
to your search text and try it. 将fish
替换为您的搜索文本,然后尝试。
List<DataGridViewColumn> Cols = dataGridView1.Columns.Cast<DataGridViewColumn>().Where(c => c.HeaderText.Contains("fish")).ToList();
if (Cols.Count > 0)
{
dataGridView1.FirstDisplayedScrollingColumnIndex = Cols[0].Index;
}
Above code will scroll down datagridview horizontally to show searched text in column names. 上面的代码将水平向下滚动datagridview以在列名中显示搜索到的文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.