@@ -1380,7 +1380,11 @@ private void buttonManualInstallAdd_Click(object sender, EventArgs e)
13801380 {
13811381 In_buttonManualInstallAdd_Click = true ;
13821382
1383- int currentIndex = dataGridViewManualInstall . CurrentCell . RowIndex ;
1383+ int currentIndex = - 1 ;
1384+ if ( dataGridViewManualInstall . CurrentCell != null )
1385+ {
1386+ currentIndex = dataGridViewManualInstall . CurrentCell . RowIndex ;
1387+ }
13841388 int addedIndex = dataGridViewManualInstall . Rows . Add ( ) ;
13851389 dataGridViewManualInstall . Rows [ addedIndex ] . Selected = true ;
13861390 dataGridViewManualInstall . FirstDisplayedScrollingRowIndex = addedIndex ;
@@ -1400,10 +1404,13 @@ private void buttonManualInstallAdd_Click(object sender, EventArgs e)
14001404 }
14011405 else
14021406 {
1403- // Cancel, set focus back to where is was and remove the empty row
1404- dataGridViewManualInstall . CurrentCell = dataGridViewManualInstall . Rows [ currentIndex ] . Cells [ 0 ] ;
1405- dataGridViewManualInstall . Rows [ currentIndex ] . Selected = true ;
1406- dataGridViewManualInstall . FirstDisplayedScrollingRowIndex = currentIndex ;
1407+ if ( currentIndex > - 1 )
1408+ {
1409+ // Cancel, set focus back to where is was and remove the empty row
1410+ dataGridViewManualInstall . CurrentCell = dataGridViewManualInstall . Rows [ currentIndex ] . Cells [ 0 ] ;
1411+ dataGridViewManualInstall . Rows [ currentIndex ] . Selected = true ;
1412+ dataGridViewManualInstall . FirstDisplayedScrollingRowIndex = currentIndex ;
1413+ }
14071414
14081415 dataGridViewManualInstall . Rows . Remove ( dataGridViewManualInstall . Rows [ addedIndex ] ) ;
14091416 }
@@ -1424,27 +1431,30 @@ private void buttonManualInstallDelete_Click(object sender, EventArgs e)
14241431
14251432 private void setTextBoxesManualInstall ( )
14261433 {
1427- string route = dataGridViewManualInstall . CurrentRow . Cells [ 0 ] . Value . ToString ( ) ;
1428- string path = dataGridViewManualInstall . CurrentRow . Cells [ 1 ] . Value . ToString ( ) ;
1429-
1430- if ( ! AutoInstallRoutes . ContainsKey ( route ) )
1431- {
1432- // route not automatically installed
1433- textBoxManualInstallRoute . Text = route ;
1434- textBoxManualInstallPath . Text = path ;
1435- textBoxManualInstallRoute . Enabled = true ;
1436- textBoxManualInstallPath . Enabled = true ;
1437- buttonManualInstallBrowse . Enabled = true ;
1438- buttonManualInstallDelete . Enabled = true ;
1439- }
1440- else
1434+ if ( dataGridViewManualInstall . CurrentRow != null )
14411435 {
1442- textBoxManualInstallRoute . Text = "" ;
1443- textBoxManualInstallPath . Text = "" ;
1444- textBoxManualInstallRoute . Enabled = false ;
1445- textBoxManualInstallPath . Enabled = false ;
1446- buttonManualInstallBrowse . Enabled = false ;
1447- buttonManualInstallDelete . Enabled = false ;
1436+ string route = dataGridViewManualInstall . CurrentRow . Cells [ 0 ] . Value . ToString ( ) ;
1437+ string path = dataGridViewManualInstall . CurrentRow . Cells [ 1 ] . Value . ToString ( ) ;
1438+
1439+ if ( ! AutoInstallRoutes . ContainsKey ( route ) )
1440+ {
1441+ // route not automatically installed
1442+ textBoxManualInstallRoute . Text = route ;
1443+ textBoxManualInstallPath . Text = path ;
1444+ textBoxManualInstallRoute . Enabled = true ;
1445+ textBoxManualInstallPath . Enabled = true ;
1446+ buttonManualInstallBrowse . Enabled = true ;
1447+ buttonManualInstallDelete . Enabled = true ;
1448+ }
1449+ else
1450+ {
1451+ textBoxManualInstallRoute . Text = "" ;
1452+ textBoxManualInstallPath . Text = "" ;
1453+ textBoxManualInstallRoute . Enabled = false ;
1454+ textBoxManualInstallPath . Enabled = false ;
1455+ buttonManualInstallBrowse . Enabled = false ;
1456+ buttonManualInstallDelete . Enabled = false ;
1457+ }
14481458 }
14491459 }
14501460
0 commit comments