locked
GridView with Scroll RRS feed

  • Question

  • Hi to all,

    I have build Windows application using c#, i can get record in Gridview it display fine.i need to display scroll bar  when record will display more than 15 records otherwise wont display scroll bar please give solution as soon as possible.

    Thursday, February 21, 2013 2:22 PM

Answers

  • dataGridView1.ScrollBars = ScrollBars.None;
    if (dataGridView1.RowCount > 15) 
    {
       dataGridView1.ScrollBars = ScrollBars.Vertical;
       dataGridView1.Width = .Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + 21; // 21 is scrollbar width
    }
    else
     { dataGridView1.Width = .Columns.GetColumnsWidth (DataGridViewElementStates.Visible);
    }


    It all Happenz Sendil

    • Proposed as answer by sendilg Friday, February 22, 2013 8:56 AM
    • Marked as answer by Bob Wu-MT Monday, February 25, 2013 7:54 AM
    Thursday, February 21, 2013 5:41 PM

  • //Working fine this code 
    
    dataGridView1.ScrollBars = ScrollBars.None;
    if (dataGridView1.RowCount > 15) 
    {
       dataGridView1.ScrollBars = ScrollBars.Vertical;
       dataGridView1.Width = dataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + 21; // 21 is scrollbar width
    }
    else
     { dataGridView1.Width = dataGridView1.Columns.GetColumnsWidth (DataGridViewElementStates.Visible);
    }

    Dear Sendilg,Thanks to give Solution to me.its very helpful to me. but you have missed One word in your code like this//dataGridView1.Columns,

     


    • Marked as answer by Jio333 Sunday, February 24, 2013 5:58 AM
    Saturday, February 23, 2013 10:08 AM

All replies

  • dataGridView1.ScrollBars = ScrollBars.None;
    if (dataGridView1.RowCount > 15) 
    {
       dataGridView1.ScrollBars = ScrollBars.Vertical;
       dataGridView1.Width = .Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + 21; // 21 is scrollbar width
    }
    else
     { dataGridView1.Width = .Columns.GetColumnsWidth (DataGridViewElementStates.Visible);
    }


    It all Happenz Sendil

    • Proposed as answer by sendilg Friday, February 22, 2013 8:56 AM
    • Marked as answer by Bob Wu-MT Monday, February 25, 2013 7:54 AM
    Thursday, February 21, 2013 5:41 PM

  • //Working fine this code 
    
    dataGridView1.ScrollBars = ScrollBars.None;
    if (dataGridView1.RowCount > 15) 
    {
       dataGridView1.ScrollBars = ScrollBars.Vertical;
       dataGridView1.Width = dataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + 21; // 21 is scrollbar width
    }
    else
     { dataGridView1.Width = dataGridView1.Columns.GetColumnsWidth (DataGridViewElementStates.Visible);
    }

    Dear Sendilg,Thanks to give Solution to me.its very helpful to me. but you have missed One word in your code like this//dataGridView1.Columns,

     


    • Marked as answer by Jio333 Sunday, February 24, 2013 5:58 AM
    Saturday, February 23, 2013 10:08 AM
  • Hi Ingru

    Mark the response as Answered if you the post have solved your query.

    Vote if it was helpful.


    It all Happenz Sendil

    Sunday, February 24, 2013 4:00 AM