c# - Auto scroll the DataGridView does not work when AllowUserToAddRows = false -


i want datagridview display data(readonly), , user can not enter data through datagridview directly, rather through datasource , datamember. prevent users enter data, did set:

m_dview.allowusertoaddrows = false;

why after set it, datagridview auto scroll not work?

m_dview.datasource = ds; m_dview.datamember = dm; m_dview.autogeneratecolumns = true; m_dview.multiselect = false; m_dview.selectionmode = datagridviewselectionmode.fullrowselect; m_dview.autosizecolumnsmode = datagridviewautosizecolumnsmode.allcells; m_dview.readonly = true; m_dview.allowusertoaddrows = false; m_dview.allowusertodeleterows = false; m_dview.allowusertoordercolumns = false; m_dview.autosizerowsmode = datagridviewautosizerowsmode.allcells; m_dview.allowusertoresizecolumns = false; m_dview.columnheadersheightsizemode = datagridviewcolumnheadersheightsizemode.disableresizing; m_dview.allowusertoresizerows = false; m_dview.rowheaderswidthsizemode = datagridviewrowheaderswidthsizemode.disableresizing;  // auto scroll worked when m_dview.allowusertoaddrows = true; if (m_dview.rows.count > 0) {     m_dview.currentcell = m_dview.rows[m_dview.rows.count - 1].cells[0]; } 

i have created code sample shown below , works perfectly. dragged , dropped datagridview control on new form shown below , named m_dview

created button when clicked run code sample below

using (sqlconnection c = new sqlconnection("server=localhost;database=deno;trusted_connection=true;"))             {                 c.open();                  using (sqldataadapter = new sqldataadapter(                     "select * test", c))                 {                     // 3                     // use dataadapter fill datatable                     string dm = "testscroll";                     dataset ds = new dataset();                     a.fill(ds, dm);                     // 4                     // render data onto screen                     m_dview.allowusertoaddrows = false;                     m_dview.datasource = ds;                     m_dview.datamember = dm;                     m_dview.autogeneratecolumns = true;                     m_dview.multiselect = false;                     m_dview.selectionmode = datagridviewselectionmode.fullrowselect;                     m_dview.autosizecolumnsmode = datagridviewautosizecolumnsmode.allcells;                     m_dview.readonly = true;                     m_dview.allowusertoaddrows = false;                     m_dview.allowusertodeleterows = false;                     m_dview.allowusertoordercolumns = false;                     m_dview.autosizerowsmode = datagridviewautosizerowsmode.allcells;                     m_dview.allowusertoresizecolumns = false;                     m_dview.columnheadersheightsizemode = datagridviewcolumnheadersheightsizemode.disableresizing;                     m_dview.allowusertoresizerows = false;                     m_dview.rowheaderswidthsizemode = datagridviewrowheaderswidthsizemode.disableresizing;                  }                 m_dview.firstdisplayedscrollingrowindex = m_dview.rows.count-1;             } 

i have scrolled gridview last row using datagridview.firstdisplayedscrollingrowindex property

for example

m_dview.firstdisplayedscrollingrowindex = m_dview.rows.count-1; 

can copy , paste following code new project , test? other problem real culprit.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -