HighTechTalks DotNet Forums  

VS2005 - DefaultValuesNeeded - bug? Adding default values in DataGridView

Dotnet FAQs microsoft.public.dotnet.faqs


Discuss VS2005 - DefaultValuesNeeded - bug? Adding default values in DataGridView in the Dotnet FAQs forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
dbuchanan
 
Posts: n/a

Default VS2005 - DefaultValuesNeeded - bug? Adding default values in DataGridView - 12-01-2005 , 06:43 PM






Hello,

Is this a bug?
Is there some kind of work around?

I want to add default values for a few columns in my datagridview

I found the "DefaultValuesNeeded" event for the datagridview

I gave it a try using the example given in

http://msdn2.microsoft.com/en-us/lib...snee ded.aspx

Here is my code
\\
Private Sub dgvDeviceTypes_DefaultValuesNeeded(ByVal sender As
Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs)
Handles dgvDeviceTypes.DefaultValuesNeeded
'enter default values into lkpDeviceTypes
With e.Row
.Cells("dtHide").Value = False
.Cells("dtOrd").Value = 0
.Cells("bMachType").Value = True

End With
End Sub
//

I get the following error;
-----------------------
Column named rEditedBy cannot be found.
Parameter name: columnName
-----------------------


Here is my table;

pkDeviceTypeId smallint
DeviceName varchar(20)
Prefix char(4)
bMachType bit
dtOrd tinyint
dtHide bit


Below is the text of the error - Notice that the code cannot find the
column name. It seems that it thinks the column name is "columnName";

System.ArgumentException was unhandled
Message="Column named rEditedBy cannot be found.
Parameter name: columnName"
ParamName="columnName"
Source="System.Windows.Forms"
StackTrace:
at
System.Windows.Forms.DataGridViewCellCollection.ge t_Item(String
columnName)
at
QmsUI.f080AdminSetup.dgvLaborCostCodes_DefaultValu esNeeded(Object
sender, DataGridViewRowEventArgs e) in D:\DBuchanan MyDocuments\Visual
Studio 2005\Projects\Qms_01\QmsUI\Form1.vb:line 287
at
System.Windows.Forms.DataGridView.OnDefaultValuesN eeded(DataGridViewRowEventArgs
e)
at
System.Windows.Forms.DataGridView.OnRowEnter(DataG ridViewCell&
dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean
canCreateNewRow, Boolean validationFailureOccurred)
at
System.Windows.Forms.DataGridView.SetCurrentCellAd dressCore(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(Mous eEventArgs
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.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext
context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at QmsUI.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


Is this a bug?
Is there some kind of work around?

thank you,
dbuchanan


Reply With Quote
  #2  
Old   
dbuchanan
 
Posts: n/a

Default Re: VS2005 - DefaultValuesNeeded - bug? Adding default values in DataGridView - 12-03-2005 , 11:09 AM






Hi Gabriel,

I'm sorry!

I sent the code for the wrong table. Here it is again - the code and
error match this time right this time.

Here is the error message;
--------------------------
Column named rEditedBy cannot be found.
Parameter name: columnName
--------------------------


Here is the code where the error occurs
\\
Private Sub dgvLaborCostCodes_DefaultValuesNeeded(ByVal sender As
Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs)
Handles dgvLaborCostCodes.DefaultValuesNeeded
'enter default values into lkpLaborCostCodes
With e.Row
.Cells("rEditedBy").Value = My.User.Name '<< This
line
.Cells("rEditedOn").Value = Now
End With
End Sub
//


Here is the data table that is behind the dataGridView
\\
CREATE TABLE [lkpLaborCostCodeRate] (
[pkLaborCostCodeRateId] [smallint] IDENTITY (1, 1) NOT NULL ,
[LaborCostCode] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL ,
[HourlyRate] [smallmoney] NOT NULL ,
[rEditedOn] [smalldatetime] NOT NULL , --< I tried to give a
default value for this field
[rEditedBy] [smalldatetime] NOT NULL ,
CONSTRAINT [PK_lkpLaborCostCodeRates] PRIMARY KEY CLUSTERED
(
[pkLaborCostCodeRateId]
) WITH FILLFACTOR = 90 ON [PRIMARY]
) ON [PRIMARY]
GO
//


Here is the error I get when I click into the datagrid and the
'DefaultValuesNeeded' event fires
\\
System.ArgumentException was unhandled
Message="Column named rEditedBy cannot be found.
Parameter name: columnName"
ParamName="columnName"
Source="System.Windows.Forms"
StackTrace:
at
System.Windows.Forms.DataGridViewCellCollection.ge t_Item(String
columnName)
at
QmsUI.f080AdminSetup.dgvLaborCostCodes_DefaultValu esNeeded(Object
sender, DataGridViewRowEventArgs e) in D:\DBuchanan MyDocuments\Visual
Studio 2005\Projects\Qms_01\QmsUI\AdminSetup.vb:line 286
at
System.Windows.Forms.DataGridView.OnDefaultValuesN eeded(DataGridViewRowEventArgs
e)
at
System.Windows.Forms.DataGridView.OnRowEnter(DataG ridViewCell&
dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean
canCreateNewRow, Boolean validationFailureOccurred)
at
System.Windows.Forms.DataGridView.SetCurrentCellAd dressCore(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(Mous eEventArgs
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.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext
context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at QmsUI.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
//


Is this a bug?
Is there some kind of work around?


dbuchanan


Reply With Quote
  #3  
Old   
Sergio Torres
 
Posts: n/a

Default RE: VS2005 - DefaultValuesNeeded - bug? Adding default values in DataG - 12-03-2005 , 11:26 AM



Hi There,

The same happened to me. I checked the datagridview properties at run time
(using the locals windows) and column names are all "" (an empty string?).

I solved it using the columns numbers instead of columns name.

i.e. use ".Cells(0).Value = False" instead of ".Cells("dtHide").Value = False"

I hope this helps,



--
Sergio Torres C.
(505) 897 2041
___________________
http://www.stcsys.com
___________________



"dbuchanan" wrote:

Quote:
Hello,

Is this a bug?
Is there some kind of work around?

I want to add default values for a few columns in my datagridview

I found the "DefaultValuesNeeded" event for the datagridview

I gave it a try using the example given in

http://msdn2.microsoft.com/en-us/lib...snee ded.aspx

Here is my code
\\
Private Sub dgvDeviceTypes_DefaultValuesNeeded(ByVal sender As
Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs)
Handles dgvDeviceTypes.DefaultValuesNeeded
'enter default values into lkpDeviceTypes
With e.Row
.Cells("dtHide").Value = False
.Cells("dtOrd").Value = 0
.Cells("bMachType").Value = True

End With
End Sub
//

I get the following error;
-----------------------
Column named rEditedBy cannot be found.
Parameter name: columnName
-----------------------


Here is my table;

pkDeviceTypeId smallint
DeviceName varchar(20)
Prefix char(4)
bMachType bit
dtOrd tinyint
dtHide bit


Below is the text of the error - Notice that the code cannot find the
column name. It seems that it thinks the column name is "columnName";

System.ArgumentException was unhandled
Message="Column named rEditedBy cannot be found.
Parameter name: columnName"
ParamName="columnName"
Source="System.Windows.Forms"
StackTrace:
at
System.Windows.Forms.DataGridViewCellCollection.ge t_Item(String
columnName)
at
QmsUI.f080AdminSetup.dgvLaborCostCodes_DefaultValu esNeeded(Object
sender, DataGridViewRowEventArgs e) in D:\DBuchanan MyDocuments\Visual
Studio 2005\Projects\Qms_01\QmsUI\Form1.vb:line 287
at
System.Windows.Forms.DataGridView.OnDefaultValuesN eeded(DataGridViewRowEventArgs
e)
at
System.Windows.Forms.DataGridView.OnRowEnter(DataG ridViewCell&
dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean
canCreateNewRow, Boolean validationFailureOccurred)
at
System.Windows.Forms.DataGridView.SetCurrentCellAd dressCore(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(Mous eEventArgs
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.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext
context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at QmsUI.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


Is this a bug?
Is there some kind of work around?

thank you,
dbuchanan



Reply With Quote
  #4  
Old   
AT
 
Posts: n/a

Default Re: VS2005 - DefaultValuesNeeded - bug? Adding default values in DataG - 12-08-2005 , 11:05 AM



Hello,

To find the column name, select your datagridview and go into edit
columns. Pick a column on the left pane and check the (name) property
on the right pane. This is the name you need to use in the code and by
default it goes something like "columnnameDataGridViewTextBoxColumn". I
renamed each name to something shorter.

Hope this helps,
Dom


Reply With Quote
  #5  
Old   
dbuchanan
 
Posts: n/a

Default Re: VS2005 - DefaultValuesNeeded - bug? Adding default values in DataG - 12-08-2005 , 12:47 PM



Dominic,

I can't get it to work. When I use this code as you instructed like
this..

\\
Private Sub dgvDeviceTypes_DefaultValuesNeeded(ByVal sender As Object,
ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles
dgvDeviceTypes.DefaultValuesNeeded
'enter default values into lkpDeviceTypes
With e.Row
'0' based, counting only displayed columns
.Cells("BMachTypeDataGridViewCheckBoxColumn").Valu e = 0
'bMachType
.Cells("DtHideDataGridViewCheckBoxColumn").Value = 0
'dtHide
End With
End Sub
//

....I get the following error
\\
System.IO.FileLoadException was unhandled
Message="The given assembly name or codebase was invalid. (Exception
from HRESULT: 0x80131047)"
Source="QmsUI"
StackTrace:
at QmsUI.f080AdminSetup.cboSelectTable_TextChanged(Ob ject
sender, EventArgs e)
at System.Windows.Forms.Control.OnTextChanged(EventAr gs e)
at System.Windows.Forms.ComboBox.OnTextChanged(EventA rgs e)
at System.Windows.Forms.Control.set_Text(String value)
at System.Windows.Forms.ComboBox.set_Text(String value)
at System.Windows.Forms.ComboBox.UpdateText()
at System.Windows.Forms.ComboBox.WmReflectCommand(Mes sage& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.SendMessa ge(HandleRef hWnd,
Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr
wparam, IntPtr lparam)
at System.Windows.Forms.Control.ReflectMessageInterna l(IntPtr
hWnd, Message& m)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.CallWindo wProc(IntPtr wndProc,
IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Messa ge& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext
context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at QmsUI.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
//


However, when I follow Sergio's suggestion (using the 0 based index of
displayed columns in the dgv) like this;
\\
Private Sub dgvDeviceTypes_DefaultValuesNeeded(ByVal sender As Object,
ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles
dgvDeviceTypes.DefaultValuesNeeded
'enter default values into lkpDeviceTypes
With e.Row
'0' based, counting only displayed columns
.Cells(2).Value = 0 'bMachType
.Cells(4).Value = 0 'dtHide
End With
End Sub
//

I get no error. and it works.

I would prefer following your suggestion if it worked, because then I
don't have to recount columns or change the code when I remove a column
from the dgv.

Please help me understand just what you mean.

Thank you,
dbuchanan


Reply With Quote
  #6  
Old   
dbuchanan
 
Posts: n/a

Default Re: VS2005 - DefaultValuesNeeded - bug? Adding default values in DataG - 12-08-2005 , 02:23 PM



Hi Dominic,

I appologize, - that error was unrelated to your solution.

I didn't understand it and it happened immediately after I tried your
solution.

Your method works! Thankyou for your input.

dbuchanan


Reply With Quote
  #7  
Old   
jtsmith2
 
Posts: n/a

Default Re: VS2005 - DefaultValuesNeeded - bug? Adding default values in DataGridView - 05-23-2006 , 01:09 PM




Was this issue ever fixed? I am having the same problem in my code. I
have a table and when I try to reference a column by its columnName it
throws the above error.



--
jtsmith2
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message2003241.html


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.