Click here to Skip to main content
15,910,981 members
Home / Discussions / C#
   

C#

 
Questionbehavior of Value Tuples in .NET 4.7 Pin
BillWoodruff19-Jun-17 6:24
professionalBillWoodruff19-Jun-17 6:24 
AnswerRe: behavior of Value Tuples in .NET 4.7 Pin
Nathan Minier19-Jun-17 7:05
professionalNathan Minier19-Jun-17 7:05 
GeneralRe: behavior of Value Tuples in .NET 4.7 Pin
BillWoodruff20-Jun-17 6:36
professionalBillWoodruff20-Jun-17 6:36 
GeneralRe: behavior of Value Tuples in .NET 4.7 Pin
Nathan Minier20-Jun-17 7:34
professionalNathan Minier20-Jun-17 7:34 
AnswerRe: behavior of Value Tuples in .NET 4.7 Pin
Eddy Vluggen19-Jun-17 21:55
professionalEddy Vluggen19-Jun-17 21:55 
GeneralRe: behavior of Value Tuples in .NET 4.7 Pin
BillWoodruff20-Jun-17 6:34
professionalBillWoodruff20-Jun-17 6:34 
GeneralRe: behavior of Value Tuples in .NET 4.7 Pin
Eddy Vluggen20-Jun-17 8:37
professionalEddy Vluggen20-Jun-17 8:37 
GeneralRe: behavior of Value Tuples in .NET 4.7 Pin
BillWoodruff20-Jun-17 15:39
professionalBillWoodruff20-Jun-17 15:39 
GeneralRe: behavior of Value Tuples in .NET 4.7 Pin
Eddy Vluggen21-Jun-17 3:45
professionalEddy Vluggen21-Jun-17 3:45 
AnswerRe: behavior of Value Tuples in .NET 4.7 Pin
Bernhard Hiller19-Jun-17 22:46
Bernhard Hiller19-Jun-17 22:46 
GeneralRe: behavior of Value Tuples in .NET 4.7 Pin
BillWoodruff20-Jun-17 6:44
professionalBillWoodruff20-Jun-17 6:44 
AnswerRe: behavior of Value Tuples in .NET 4.7 Pin
Richard Deeming20-Jun-17 0:50
mveRichard Deeming20-Jun-17 0:50 
GeneralRe: behavior of Value Tuples in .NET 4.7 Pin
BillWoodruff20-Jun-17 6:50
professionalBillWoodruff20-Jun-17 6:50 
AnswerRe: behavior of Value Tuples in .NET 4.7 Pin
Gerry Schmitz21-Jun-17 3:15
mveGerry Schmitz21-Jun-17 3:15 
QuestionRemoving an element from the content of a string value which is HTML code Pin
Farhad Eft19-Jun-17 1:55
Farhad Eft19-Jun-17 1:55 
AnswerRe: Removing an element from the content of a string value which is HTML code Pin
OriginalGriff19-Jun-17 2:12
mveOriginalGriff19-Jun-17 2:12 
GeneralRe: Removing an element from the content of a string value which is HTML code Pin
Farhad Eft19-Jun-17 2:46
Farhad Eft19-Jun-17 2:46 
GeneralRe: Removing an element from the content of a string value which is HTML code Pin
OriginalGriff19-Jun-17 2:55
mveOriginalGriff19-Jun-17 2:55 
QuestionWindows media player issue Pin
Member 1326418716-Jun-17 20:37
Member 1326418716-Jun-17 20:37 
AnswerRe: Windows media player issue Pin
OriginalGriff16-Jun-17 21:34
mveOriginalGriff16-Jun-17 21:34 
QuestionChanging an Image during runtime from resources Pin
Member 1319657416-Jun-17 5:10
Member 1319657416-Jun-17 5:10 
AnswerRe: Changing an Image during runtime from resources Pin
BillWoodruff17-Jun-17 13:12
professionalBillWoodruff17-Jun-17 13:12 
QuestionSystem.IndexOutOfRangeException Pin
joost.versteegen14-Jun-17 21:46
joost.versteegen14-Jun-17 21:46 
Hi,
I have a weird problem, hopefully someone can shine a light on it?

The user gets a list of defects on a product from the database. I put them in a List<drumdefect>, like so:
C#
while (rdr.Read())
            {
              DrumDefect defect = new DrumDefect()
              {
                AVI_Defect = new AVIDefect()
                {
                  SequenceNumber = (rdr["AVIProdUDefectSeqNr"] != DBNull.Value) ? int.Parse(rdr["AVIProdUDefectSeqNr"].ToString()) : (rdr["MVIProdUDefectSeqNr"] != DBNull.Value) ? int.Parse(rdr["MVIProdUDefectSeqNr"].ToString()) : -1,
                  Code = (rdr["AVIProdUDefectCode"] == DBNull.Value) ? "# 0" : rdr["AVIProdUDefectCode"].ToString(),
                  Name = (rdr["AVIProdUDefectName"] == DBNull.Value) ? "NODEFECT" : rdr["AVIProdUDefectName"].ToString(),
                  Severity = (rdr["AVISeverityLevelID"] == DBNull.Value) ? DefectSeverity.NODEFECT : (DefectSeverity)int.Parse(rdr["AVISeverityLevelID"].ToString())
                },
                MVI_Defect = new Defect()
                {
                  Code = (rdr["MVIProdUDefectCode"] == DBNull.Value) ? "# 0" : rdr["MVIProdUDefectCode"].ToString(),
                  Name = (rdr["MVIProdUDefectName"] == DBNull.Value) ? "NODEFECT" : rdr["MVIProdUDefectName"].ToString(),
                  Severity = (rdr["MVISeverityLevelID"] == DBNull.Value) ? DefectSeverity.NODEFECT : (DefectSeverity)int.Parse(rdr["MVISeverityLevelID"].ToString())
                },
                FVI_Defect = new Defect()
              };
              list.Add(defect);
     }

Then I import them in a datagridview like so:
C#
_SelectedDrum.Defects = database.GetList();

dataGridViewDefects.DataSource = null;
dataGridViewDefects.DataSource = _SelectedDrum.Defects;
dataGridViewDefects.Refresh();


The user can add a defect, so I add one like this:
C#
DrumDefect defect = new DrumDefect()
{
   AVI_Defect = new AVIDefect()
   {
     SequenceNumber = -1,
     Code = "# 0",
     Name = "NODEFECT",
     Severity = DefectSeverity.NODEFECT
   },
   MVI_Defect = new Defect()
   {
     Code = "# 0",
     Name = "NODEFECT",
     Severity = DefectSeverity.NODEFECT
   },
   FVI_Defect = new Defect()
 };
 _SelectedDrum.Defects.Add(defect);

it all works fine, except when the database list is empty, the user adds a defect, and you click with the mouse in the datagridview (but only at the click), then the application crashes with this error:
System.IndexOutOfRangeException occurred
  Message=Index -1 does not have a value.
  Source=System.Windows.Forms
  StackTrace:
       at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
       at System.Windows.Forms.CurrencyManager.get_Current()
       at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs e)
       at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred)
       at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
       at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown)
       at System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
       at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
       at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.DataGridView.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Xerox.ODB2.twister.Program.Main() in c:\Users\y952hrym\Documents\CS_Projects_2\Twister\Twister\Twister.View\Program.cs:line 18
  InnerException: 

Thanks

modified 15-Jun-17 4:22am.

AnswerRe: System.IndexOutOfRangeException Pin
OriginalGriff14-Jun-17 22:19
mveOriginalGriff14-Jun-17 22:19 
GeneralRe: System.IndexOutOfRangeException Pin
joost.versteegen14-Jun-17 22:26
joost.versteegen14-Jun-17 22:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.