>>I need to lock my bottom (Totals) row on a data grid yet allow all others to be edited. Any ideas?
>>
>>Thanks in advance,
>
>I found the answer and I wanted to share it with the
UT! Put this in your bag of tricks. I'm sending this in to the VBPJ Tips guys.
>
>Private Sub MarketGrid_BeforeColEdit(ByVal ColIndex As Integer, ByVal KeyAscii As Integer, Cancel As Integer)
> strText = MarketGrid.Text ' Save what the origional was
>
> If MarketGrid.Row = 2 Then ' This could be any row
> ' MsgBox "This Row can not be edited"
> Cancel = True ' Dont effect changes
> MarketGrid.Text = strText ' Make sure that the text remains the same
> End If
>
>End Sub
>
Here is what I sent to VBPJ I included the plug for UT hopeing that if they publish we might get some more VB guys in here.
I needed to lock a row on a grid to show totals as well as a percentage row that needed to remain read only to the user. I didn't want to add another grid with a single row for totals as it didn't have the flexability I needed. After some searching on exellent resource sites like
www.levelextreme.com I found that this was a common issue so after much hair-pulling and caffinated beverage came the very simple and very basic answer in 1 line of code! Enjoy.
Private Sub MyDBGrid_KeyPress(KeyAscii As Integer)
If MyDBGrid.Row = MyTotalsRow Then KeyAscii = vbNull ' Whatever row you want to be locked
End Sub
~Joe Johnston USA
"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams