473,387 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DataGrid Conditional ReadOnly Cell

Hi,
I needed to make a TextBox on a DataGrid ReadOnly based on the condition of
another cell on its row.

I achieved this using a Custom Data Column Class "DacDGTextColLotNo" but I
can't get the TextBox to display its value when you leave the TextBox.

I figure that I need to use the SetColumnValueAtRow Method but I am
struggling to understand how.

I would appreciate any guidance.

My Create Grid Style Code on the Form:
........
CreateGridStyle = New DataGridTableStyle
........
........
If PurchStyle <> 1 Then
'Set Lot Nos Column
Dim DGTxtBoxLotNo AS New DacDGTextColLotNo
With DGTxtBoxLotNo
.MappingName = "LotNo"
.HeaderText = "Lot"
.Width = 50
.Alignment = HorizontalAlignment.Left
.NullText = ""
.Format = ""
.ReadOnly = True

End With

CreateGridStyle.GridColumnStyles.Add(DGTxtBoxLotNo )

..........

My Custom Column Style Class Code:

Public Class DataGridTextBoxColumn

Inherits DataGridTextBoxColumn

Public Sub New()
MyBase.New()
Me.MappingName = MappingName
Me.Format = Format
Me.Alignment = Alignment
Me.Width = Width
Me.ReadOnly = ReadOnly
Me.Headertext = Headertext
Me.NullText = NullText
End Sub

Protected Overrides Function GetColumnValueAtRow _
(ByVal source As System.Windows.Forms.CurrencyManager, _
ByVal rowNum As Integer) As Object

Dim drv As DataRowView = CType([source].Current, DataRowView)
Try
Me.ReadOnly = Cint(drv("LotFlg")) <> 2
Catch
Me.ReadOnly = True
End try

End Function

End Class
Thanks

Doug

Nov 21 '05 #1
4 2481
DataGrid just displays data from datasource, let's say from datatable. When
you change data in textbox, there is nothing changed in datatable. Then you
leave the textbox, DacDGTextColLotNo needs update data in datatable which is
done by SetColumnValueAtRow Method.
Nov 21 '05 #2
As said in my question, I figured that SetColumnValueAtRow Method was
required!

But the basis of my question was that I have not been able to work out how
to get it to work.
Doug
"Rulin Hong" <Ru*******@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
DataGrid just displays data from datasource, let's say from datatable. When you change data in textbox, there is nothing changed in datatable. Then you leave the textbox, DacDGTextColLotNo needs update data in datatable which is done by SetColumnValueAtRow Method.

Nov 21 '05 #3
In fact the data entered is passed to the underlying DataTable, it is just
not being displayed in the cell whenever you mover to another row or column?

So does that indicate that SetColumnValueAtRow is not an issue?

Where else do I look?

"Rulin Hong" <Ru*******@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
DataGrid just displays data from datasource, let's say from datatable. When you change data in textbox, there is nothing changed in datatable. Then you leave the textbox, DacDGTextColLotNo needs update data in datatable which is done by SetColumnValueAtRow Method.

Nov 21 '05 #4
Hi,
I have resolved this problem.

For anyone interested, I believe that the problem was occuring because my
Class DataGridTextBoxColumn function "GetColumnValueAtRow" was over-riding
the Base method and the Row/Column value was not being writen back to the
Grid
The following code works:
Public Class DataGridTextBoxColumn

Inherits DataGridTextBoxColumn

Public Sub New()
MyBase.New()
Me.MappingName = MappingName
Me.Format = Format
Me.Alignment = Alignment
Me.Width = Width
Me.ReadOnly = ReadOnly
Me.Headertext = Headertext
Me.NullText = NullText
End Sub

Protected Overrides Function GetColumnValueAtRow _
(ByVal source As System.Windows.Forms.CurrencyManager, _
ByVal rowNum As Integer) As Object

Dim s as Object = MyBase.GetColumnValueAtRow([source], rowNum)
Dim drv As DataRowView = CType([source].Current, DataRowView)
Dim fReadOnly As Boolean
Try
fReadOnly = drv("LotFlg").ToString <> "2"
Catch
fReadOnly = True
End try

Me.ReadOnly = fReadOnly

Return s

End Function

Doug
"Doug Bell" <dug@bigpond> wrote in message
news:ea*************@TK2MSFTNGP14.phx.gbl...
Hi,
I needed to make a TextBox on a DataGrid ReadOnly based on the condition of another cell on its row.

I achieved this using a Custom Data Column Class "DacDGTextColLotNo" but I
can't get the TextBox to display its value when you leave the TextBox.

I figure that I need to use the SetColumnValueAtRow Method but I am
struggling to understand how.

I would appreciate any guidance.

My Create Grid Style Code on the Form:
.......
CreateGridStyle = New DataGridTableStyle
.......
.......
If PurchStyle <> 1 Then
'Set Lot Nos Column
Dim DGTxtBoxLotNo AS New DacDGTextColLotNo
With DGTxtBoxLotNo
.MappingName = "LotNo"
.HeaderText = "Lot"
.Width = 50
.Alignment = HorizontalAlignment.Left
.NullText = ""
.Format = ""
.ReadOnly = True

End With

CreateGridStyle.GridColumnStyles.Add(DGTxtBoxLotNo )

.........

My Custom Column Style Class Code:

Public Class DataGridTextBoxColumn

Inherits DataGridTextBoxColumn

Public Sub New()
MyBase.New()
Me.MappingName = MappingName
Me.Format = Format
Me.Alignment = Alignment
Me.Width = Width
Me.ReadOnly = ReadOnly
Me.Headertext = Headertext
Me.NullText = NullText
End Sub

Protected Overrides Function GetColumnValueAtRow _
(ByVal source As System.Windows.Forms.CurrencyManager, _
ByVal rowNum As Integer) As Object

Dim drv As DataRowView = CType([source].Current, DataRowView)
Try
Me.ReadOnly = Cint(drv("LotFlg")) <> 2
Catch
Me.ReadOnly = True
End try

End Function

End Class
Thanks

Doug

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Job Lot | last post by:
I have an Expense Data Entry form which contains a DataGrid showing various expense categories. There are three columns Description, Cash Exp, Credit Exp, where Description column is readonly. ...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
3
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
3
by: Lyners | last post by:
I am having a hard time with this one, and I thought it would be easy. I have a datagrid in which I have textboxs for users to enter data. One of the fields in the database behind the datagrid...
8
by: Scott Meddows | last post by:
I have a datagrid control that I've inherited from the base datagrid control (Source below). I am applying a datatable style onto the datatable that I assign as my datasource. All of my column...
4
by: John Smith | last post by:
Hi All; I am using the HeaderAndDataAlignColumn class from Ken Tucker. I have customized it for a wider row. I reposition the DrawString method so the text is centered vertically in the row. ...
2
by: Flack | last post by:
Hey guys, I have a DataGrid and DataTable field in my class : private ImageDataGrid dataGrid1; //ImageDataGrid extends dataGrid and just overides OnMouseDown private DataTable dt = new...
6
by: Doug Bell | last post by:
Hi I have a DataGrid with some hidden columns and also some read Only and some ComboBox Columns. Sandard Tabbing through the Datagrid sees the focus go to the hidden columns requiring further...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.