Click here to Skip to main content
15,898,588 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: System.IndexOutOfRangeException Pin
OriginalGriff14-Jun-17 22:38
mveOriginalGriff14-Jun-17 22:38 
GeneralRe: System.IndexOutOfRangeException Pin
joost.versteegen14-Jun-17 22:41
joost.versteegen14-Jun-17 22:41 
GeneralRe: System.IndexOutOfRangeException Pin
OriginalGriff14-Jun-17 23:01
mveOriginalGriff14-Jun-17 23:01 
GeneralRe: System.IndexOutOfRangeException Pin
joost.versteegen14-Jun-17 23:08
joost.versteegen14-Jun-17 23:08 
AnswerRe: System.IndexOutOfRangeException Pin
Richard Deeming15-Jun-17 1:39
mveRichard Deeming15-Jun-17 1:39 
GeneralRe: System.IndexOutOfRangeException Pin
joost.versteegen15-Jun-17 2:14
joost.versteegen15-Jun-17 2:14 
AnswerRe: System.IndexOutOfRangeException Pin
Gerry Schmitz16-Jun-17 5:47
mveGerry Schmitz16-Jun-17 5:47 
QuestionTCP/IP client-server Socket Programming use Video chat also in c#? Pin
prog.sidra13-Jun-17 20:03
prog.sidra13-Jun-17 20:03 
AnswerRe: TCP/IP client-server Socket Programming use Video chat also in c#? Pin
Pete O'Hanlon13-Jun-17 21:25
mvePete O'Hanlon13-Jun-17 21:25 
GeneralRe: TCP/IP client-server Socket Programming use Video chat also in c#? Pin
prog.sidra15-Jun-17 19:17
prog.sidra15-Jun-17 19:17 
GeneralRe: TCP/IP client-server Socket Programming use Video chat also in c#? Pin
Pete O'Hanlon15-Jun-17 20:42
mvePete O'Hanlon15-Jun-17 20:42 
AnswerRe: TCP/IP client-server Socket Programming use Video chat also in c#? Pin
jschell14-Jun-17 10:35
jschell14-Jun-17 10:35 
GeneralRe: TCP/IP client-server Socket Programming use Video chat also in c#? Pin
prog.sidra15-Jun-17 19:19
prog.sidra15-Jun-17 19:19 
QuestionRe: TCP/IP client-server Socket Programming use Video chat also in c#? Pin
Gerry Schmitz16-Jun-17 6:00
mveGerry Schmitz16-Jun-17 6:00 
AnswerRe: TCP/IP client-server Socket Programming use Video chat also in c#? Pin
jschell17-Jun-17 6:01
jschell17-Jun-17 6:01 

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.