locked
Vertical Scrollbar in DataGridView RRS feed

  • Question

  • Hi, 

    How do i display the vertical scrollbar in DataGridView?

     

    Monday, December 27, 2010 12:45 PM

Answers

  • Hello,

    Your issue is with the following line:

    dgvRow.Frozen  = true;

    Remove it and you shall have your scrollbars showing.

    Please mark as Answer if that helps.

    • Marked as answer by bdnp Tuesday, December 28, 2010 5:37 AM
    Monday, December 27, 2010 10:12 PM

All replies

  • You do not need to. Vertical scroll bar appears the moment the number of records cross the boundary as its auto scroll by default. So put a DGV on the form and go on adding rows..

     

    P.S. just to make sure check the ScrollBars property i not set to "None"

     


    Happy to Help :) http://vijaykamat.blogspot.com/
    Monday, December 27, 2010 12:47 PM
  • Hi vijaykamat, 

     

    I had set the ScrollBars to "Both" but still the vertical scrollbar is not coming :(

     

    Thanks 

    Monday, December 27, 2010 1:02 PM
  •  for showing only vertical scrollbar you do:

    dataGridView1.ScrollBars = ScrollBars.Vertical;

    for showing only horizontal change ".Vertical" with ".Horizontal".

    You can show both or none if you want so.

    Hope it helps,

    Mitja

    Monday, December 27, 2010 1:04 PM
  • You mean you are adding rows, but scrollbar does not appear even when the number of rows exceeds boundaries and few rows are hidden???

    That doesnt make sense. Scrollbar should appear. Check your code to see if you are changing this property to None by mistake..

    Happy to Help :) http://vijaykamat.blogspot.com/
    Monday, December 27, 2010 1:05 PM
  • yes, i am adding the rows but vertical scrollbar is  not visible. :(  
    Monday, December 27, 2010 1:08 PM
  • Can you post your code, how you are adding rows etc?

    Happy to Help :) http://vijaykamat.blogspot.com/
    Monday, December 27, 2010 1:11 PM
  • Hey, do you have enough rows in a dgv, to fill the whole height of the it?

    Becuase scrollBars appears when there is more rows to show then the full height of the dgv.

    Monday, December 27, 2010 1:15 PM
  • Dear Mitja Bonca, all the DGV will show the scroll bars only when they are full. You can not see scroll bar when the rows are less then the limits..

    Happy to Help :) http://vijaykamat.blogspot.com/
    Monday, December 27, 2010 1:18 PM
  • Hi Vijaykamat, 

    Using following source code i am filling the dataview grid. 

                dgvSmplingLotList.Rows.Clear();

                    dgvSmplingLotList.Columns.Clear();

                    dtSamplingLot.Clear();

     

                    dgvSmplingLotList.ScrollBars = ScrollBars.Both;

                    dgvSmplingLotList.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

                    dgvSmplingLotList.DoubleClick += new EventHandler(dgvSmplingLotList_DoubleClick);

                    int counter = 1;

     

                    DataGridViewCheckBoxColumn dgvChk_SelectLot = new DataGridViewCheckBoxColumn();

                    dgvChk_SelectLot.HeaderCell.Value = "Select";

                    dgvChk_SelectLot.Name = "Select";

     

                    dgvSmplingLotList.Columns.Add(dgvChk_SelectLot);

     

                    #region "Define Grid"

                    dgvSmplingLotList.Columns.Add("LotRecordID", "RecordID");

                    dgvSmplingLotList.Columns.Add("ManufacturingMonth", "Manufacturing Month");

                    dgvSmplingLotList.Columns.Add("ManufacturingMonthDisp", "Manufacturing Month");

                    dgvSmplingLotList.Columns.Add("ManufacturingYear", "Manufacturing Year");

                    dgvSmplingLotList.Columns.Add("ManufacturingYearDisp", "Manufacturing Year");

                    dgvSmplingLotList.Columns.Add("SerialNo", "SerialNo");

                    dgvSmplingLotList.Columns.Add("LotNo", "Lot Number");

                    dgvSmplingLotList.Columns.Add("StartNumber", "Start Number");

                    dgvSmplingLotList.Columns.Add("EndNumber", "End Number");

                    dgvSmplingLotList.Columns.Add("LotCreatedByUserID", "LotCreatedByUserID");

                    dgvSmplingLotList.Columns.Add("LotCreatedBy", "Lot Created By");

                    dgvSmplingLotList.Columns.Add("UserShiftID", "UserShiftID");

                    dgvSmplingLotList.Columns.Add("UserShiftTitle", "User Shift Title");

                    dgvSmplingLotList.Columns.Add("IsStartTesting", "Start Testing");

                    dgvSmplingLotList.Columns.Add("Allow_ReTesting", "Allow ReTesting");

                    dgvSmplingLotList.Columns.Add("Status", "Status");

     

                    dgvSmplingLotList.Columns["LotCreatedByUserID"].Visible = false;

                    dgvSmplingLotList.Columns["UserShiftID"].Visible = false;

                    dgvSmplingLotList.Columns["ManufacturingMonth"].Visible = false;

                    dgvSmplingLotList.Columns["ManufacturingYear"].Visible = false;

                    dgvSmplingLotList.Columns["Allow_ReTesting"].Visible = false;

                    dgvSmplingLotList.Columns["IsStartTesting"].Visible = false;

                    dgvSmplingLotList.Columns["UserShiftTitle"].Visible = false;

                    dgvSmplingLotList.Columns["ManufacturingMonth"].Visible = false;

                    dgvSmplingLotList.Columns["ManufacturingMonthDisp"].Visible = false;

                    dgvSmplingLotList.Columns["ManufacturingYear"].Visible = false;

                    dgvSmplingLotList.Columns["ManufacturingYearDisp"].Visible = false;

                    dgvSmplingLotList.Columns["LotRecordID"].Width = 60;

                    dgvSmplingLotList.Columns["StartNumber"].Width = 70;

                    dgvSmplingLotList.Columns["EndNumber"].Width = 70;

                    dgvSmplingLotList.Columns["Select"].Width = 50;

                    dgvSmplingLotList.Columns["SerialNo"].Width = 60;

                    //dgvSmplingLotList.Columns["Status"].Width = 80;

     

                    #endregion

     

                    dtSamplingLot = objSamplingLot.FillSamplingLotList();

     

                    if (dtSamplingLot.Rows.Count > 0)

                    {

     

                        foreach (DataRow dr in dtSamplingLot.Rows)

                        {

                            #region "Fill Data"

                            //if ((int.Parse(dr["IsStartTesting"].ToString()) == 0) || (int.Parse(dr["IsStartTesting"].ToString()) == -3  || int.Parse(dr["IsStartTesting"].ToString()) == -4))

                            //{

                                counter = dgvSmplingLotList.Rows.Add();

     

                                strLotNumber = DateTime.Parse(dr["ManufacturingMonth"].ToString()).Month + "/" + DateTime.Parse(dr["ManufacturingYear"].ToString()).Year + "/LOT-" + dr["SerialNo"].ToString();

     

                                DataGridViewRow dgvRow = dgvSmplingLotList.Rows[counter];

     

                                dgvRow.Cells["Select"].Value = false;

     

                                dgvRow.Cells["LotRecordID"].Value = dr["LotRecID"].ToString();

     

                                dgvRow.Cells["ManufacturingMonth"].Value = dr["ManufacturingMonth"].ToString();

     

                                dgvRow.Cells["ManufacturingMonthDisp"].Value = DateTime.Parse(dr["ManufacturingMonth"].ToString()).Month;

     

                                dgvRow.Cells["ManufacturingYear"].Value = dr["ManufacturingYear"].ToString();

     

                                dgvRow.Cells["ManufacturingYearDisp"].Value = DateTime.Parse(dr["ManufacturingYear"].ToString()).Year;

     

                                dgvRow.Cells["SerialNo"].Value = dr["SerialNo"].ToString();

     

                                dgvRow.Cells["LotNo"].Value = strLotNumber;

     

                                dgvRow.Cells["StartNumber"].Value = dr["StartNumber"].ToString();

     

                                dgvRow.Cells["EndNumber"].Value = dr["EndNumber"].ToString();

     

                                dgvRow.Cells["LotCreatedByUserID"].Value = dr["LotCreatedByUserID"].ToString();

     

                                dgvRow.Cells["LotCreatedBy"].Value = dr["LotCreatedBy"].ToString();

     

                                dgvRow.Cells["UserShiftID"].Value = dr["UserShiftID"].ToString();

     

                                dgvRow.Cells["UserShiftTitle"].Value = dr["UserShiftTitle"].ToString();

     

                                dgvRow.Cells["IsStartTesting"].Value = dr["IsStartTesting"].ToString();

     

                                dgvRow.Cells["Allow_ReTesting"].Value = dr["Allow_ReTesting"].ToString();

     

                                switch(int.Parse(dr["IsStartTesting"].ToString()))

                                {

                                    case 0:

                                        dgvRow.Cells["Status"].Value = "Lot Created";

                                        break;

     

                                    case 1:

                                        dgvRow.Cells["Status"].Value = "Available for Testing";

                                        break;

     

                                    case 2:

                                        dgvRow.Cells["Status"].Value = "Send to QA";

                                        break;

     

                                    case 3:

                                        dgvRow.Cells["Status"].Value = "Pass By QA";

                                        break;

     

                                    case 4:

                                        dgvRow.Cells["Status"].Value = "Pass By QC";

                                        break;

     

                                    case -3:

                                        dgvRow.Cells["Status"].Value = "Refuse By QA";

                                        break;

     

                                    case -4:

                                        dgvRow.Cells["Status"].Value = "Refuse By QC";

                                        break;

     

     

                                }

     

     

     

     

                                if (int.Parse(dgvRow.Cells["IsStartTesting"].Value.ToString()) == 1 || (int.Parse(dgvRow.Cells["IsStartTesting"].Value.ToString()) == -3 || int.Parse(dgvRow.Cells["IsStartTesting"].Value.ToString()) == -4))

                                {

                                    if (int.Parse(dgvRow.Cells["IsStartTesting"].Value.ToString()) == -3 || int.Parse(dgvRow.Cells["IsStartTesting"].Value.ToString()) == -4)

                                    {

                                        dgvRow.DefaultCellStyle.BackColor = Color.Red; 

                                    }

     

                                    dgvRow.Frozen  = true;

     

                                    dgvRow.ReadOnly = true;

     

     

                                }

     

                                counter++;

     

                                //dgvUserGroupList.Rows.Add(row);

                            //}

                            #endregion

                        }

     

                    }

                    // Rebind the grid and reset scrolling

                    dgvSmplingLotList.Refresh();

                    dgvSmplingLotList.FirstDisplayedScrollingRowIndex = scrollPosition;

                }

                catch (Exception ex)

                {

     

                }


     

    Monday, December 27, 2010 1:42 PM
  • Hello,

    Your issue is with the following line:

    dgvRow.Frozen  = true;

    Remove it and you shall have your scrollbars showing.

    Please mark as Answer if that helps.

    • Marked as answer by bdnp Tuesday, December 28, 2010 5:37 AM
    Monday, December 27, 2010 10:12 PM
  • Yes dbnp, I agree with Love Dot Net. Thats why its always good to take a look at the code :)

    dgvRow.Frozen  = false;//This is what you want!

    Let me know if the issue still persists.

     


    Happy to Help :) http://vijaykamat.blogspot.com/
    Tuesday, December 28, 2010 4:07 AM