Setting DataGridView Cell Properties -
05-01-2009
, 10:44 PM
I think this problem I'm experiencing is Data Binding related so I'm
reposting this message to include this group.
I'm having a problem with setting ReadOnly and ToolTipText properties for
DataGridView cells. I want to set these properties on the RowEnter event but
if I do this prior to any cell being entered I subsequently get an
InvalidArgument exception. I've found that if I set them after handling a
CellValidated event for the DGV everything works fine. I use a BindingSource
to a DataTable in my DataSet for the DGV. The DGV is on a TabControl. The
first RowEnter event occurs when I activate the tab containing the DGV. I can
set the properties during this event but once outside of my methods I get the
following error:
System.ArgumentException Message: InvalidArgument=Value of '3' is not valid
for 'rowIndex'. ParamName: NULL Data:
System.Collections.ListDictionaryInternal TargetSite:
System.Windows.Forms.DataGridViewElementStates GetState(Int32) HelpLink: NULL
Source: System.Windows.Forms StackTrace Information
********************************************* at
System.Windows.Forms.DataGridViewRow.GetState(Int3 2 rowIndex) at
System.Windows.Forms.DataGridViewRowCollection.Get NextRow(Int32 indexStart,
DataGridViewElementStates includeFilter) at
System.Windows.Forms.DataGridViewRowCollection.Get NextRow(Int32 indexStart,
DataGridViewElementStates includeFilter, DataGridViewElementStates
excludeFilter) at
System.Windows.Forms.DataGridView.CorrectRowFrozen State(DataGridViewRow
dataGridViewRow, DataGridViewElementStates rowState, Int32
anticipatedRowIndex) at
System.Windows.Forms.DataGridView.OnInsertingRow(I nt32 rowIndexInserted,
DataGridViewRow dataGridViewRow, DataGridViewElementStates rowState, Point&
newCurrentCell, Boolean firstInsertion, Int32 insertionCount, Boolean force)
at System.Windows.Forms.DataGridViewRowCollection.Ins ertDuplicateRow(Int32
indexDestination, DataGridViewRow rowTemplate, Boolean firstInsertion, Point&
newCurrentCell) at
System.Windows.Forms.DataGridViewRowCollection.Ins ertCopiesPrivate(DataGridViewRow
rowTemplate, DataGridViewElementStates rowTemplateState, Int32
indexDestination, Int32 count) at
System.Windows.Forms.DataGridViewRowCollection.Ins ertCopiesPrivate(Int32
indexSource, Int32 indexDestination, Int32 count) at
System.Windows.Forms.DataGridViewRowCollection.Add CopiesInternal(Int32
indexSource, Int32 count) at
System.Windows.Forms.DataGridView.RefreshRows(Bool ean scrollIntoView) at
System.Windows.Forms.DataGridView.OnBindingContext Changed(EventArgs e) at
System.Windows.Forms.Control.OnParentBindingContex tChanged(EventArgs e) at
System.Windows.Forms.Control.OnBindingContextChang ed(EventArgs e) at
System.Windows.Forms.Control.OnParentBindingContex tChanged(EventArgs e) at
System.Windows.Forms.Control.OnBindingContextChang ed(EventArgs e) at
System.Windows.Forms.Control.CreateControl() at
System.Windows.Forms.Control.SetVisibleCore(Boolea n value) at
System.Windows.Forms.TabControl.UpdateTabSelection (Boolean updateFocus) at
System.Windows.Forms.TabControl.OnSelectedIndexCha nged(EventArgs e) at
System.Windows.Forms.TabControl.WmSelChange() at
System.Windows.Forms.TabControl.WndProc(Message& m) at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m) at
System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr
wparam, IntPtr lparam)
This is for .NET 3.5. Any clues that you can provide that will help me
resolve this issue would be greatly appreciated?
--
Thanks,
Jerry |