By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,508 Members | 1,915 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,508 IT Pros & Developers. It's quick & easy.

VS2005 - DefaultValuesNeeded - bug? Adding default values in DataGridView

P: n/a
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...uesneeded.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

Dec 1 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Are you sure that in dgvDeviceTypes_DefaultValuesNeeded you have no
..Cells("rEditBy").Value = ... ? The error message just indicates that the
argument "columnName" of the operation
"System.Windows.Forms.DataGridViewCellCollection.g et_Item()" is not correct.

Gabriel Lozano-Morán
http://www.realdn.net
Dec 3 '05 #2

P: n/a
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

Dec 3 '05 #3

P: n/a
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:
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...uesneeded.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

Dec 3 '05 #4

P: n/a
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

Dec 8 '05 #5

P: n/a
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

Dec 8 '05 #6

P: n/a
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

Dec 8 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.