简体   繁体   中英

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.

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.

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 . Like you want to assign a one column with Fish then

row.Cells["Name"].Value = Fish.Id;

and then on click event give focus to this id .

Note:- for a better solution post your question with your code . thanks

Replace fish to your search text and try it.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM