잠토의 잠망경

DataGridView AutoScroll question 본문

공부/C sharp

DataGridView AutoScroll question

잠수함토끼 2008. 7. 3. 10:51
DataGridView AutoScroll question

Can someone please demonstrate how to use the .AutoScrollOffset method on of the DGV control? I would like to scroll the current row so that it is positioned about halfway in the visible portion of the control. Thanks...



Re: DataGridView AutoScroll question

The .AutoScrollOffset method has nothing to do with the Rows inside of the DataGridView.

To accomplish what you are trying to do, you should use the FirstDisplayedCell property along with the DisplayedRowCount property to figure out how to position your cells correctly. An example of using the FirstDisplayedCell:

Code:
DataGridView1.Rows(85).Selected = True DataGridView1.FirstDisplayedCell = DataGridView1.Rows(82).Cells(0)

This code would make my selected cell #85, the fourth cell down in the list.

------------------------------------------------------------------------------
정정합니다.
foreach (DataGridViewRow r1 in dataGridView1.Rows)
                {
                    if (sRow != null)
                    {
                        sRow.Cells[0].Style.BackColor = Color.White;
                        sRow.Cells[1].Style.BackColor = Color.White;
                        sRow.Selected = false;
                    }
                    if (Convert.ToString(r1.Cells[0].Value) == "0x" + Convert.ToString(DGVvalue, 16))
                    {
                        r1.Cells[0].Style.BackColor = Color.LightBlue;
                        r1.Cells[1].Style.BackColor = Color.LightBlue;
                        sRow = r1;
                        r1.Selected = true;
                        dataGridView1.FirstDisplayedCell = r1.Cells[0];
                        break;
                    }
                }



출처: http://www.vbforums.com/showthread.php?t=467949
Comments