473,774 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "DacDGTextColLo tNo" but I
can't get the TextBox to display its value when you leave the TextBox.

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

I would appreciate any guidance.

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

End With

CreateGridStyle .GridColumnStyl es.Add(DGTxtBox LotNo)

..........

My Custom Column Style Class Code:

Public Class DataGridTextBox Column

Inherits DataGridTextBox Column

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 GetColumnValueA tRow _
(ByVal source As System.Windows. Forms.CurrencyM anager, _
ByVal rowNum As Integer) As Object

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

End Function

End Class
Thanks

Doug

Nov 21 '05 #1
4 2508
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, DacDGTextColLot No needs update data in datatable which is
done by SetColumnValueA tRow Method.
Nov 21 '05 #2
As said in my question, I figured that SetColumnValueA tRow 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*******@disc ussions.microso ft.com> wrote in message
news:95******** *************** ***********@mic rosoft.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, DacDGTextColLot No needs update data in datatable which is done by SetColumnValueA tRow 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 SetColumnValueA tRow is not an issue?

Where else do I look?

"Rulin Hong" <Ru*******@disc ussions.microso ft.com> wrote in message
news:95******** *************** ***********@mic rosoft.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, DacDGTextColLot No needs update data in datatable which is done by SetColumnValueA tRow Method.

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

For anyone interested, I believe that the problem was occuring because my
Class DataGridTextBox Column function "GetColumnValue AtRow" 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 DataGridTextBox Column

Inherits DataGridTextBox Column

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 GetColumnValueA tRow _
(ByVal source As System.Windows. Forms.CurrencyM anager, _
ByVal rowNum As Integer) As Object

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

Me.ReadOnly = fReadOnly

Return s

End Function

Doug
"Doug Bell" <dug@bigpond> wrote in message
news:ea******** *****@TK2MSFTNG P14.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 "DacDGTextColLo tNo" but I
can't get the TextBox to display its value when you leave the TextBox.

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

I would appreciate any guidance.

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

End With

CreateGridStyle .GridColumnStyl es.Add(DGTxtBox LotNo)

.........

My Custom Column Style Class Code:

Public Class DataGridTextBox Column

Inherits DataGridTextBox Column

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 GetColumnValueA tRow _
(ByVal source As System.Windows. Forms.CurrencyM anager, _
ByVal rowNum As Integer) As Object

Dim drv As DataRowView = CType([source].Current, DataRowView)
Try
Me.ReadOnly = Cint(drv("LotFl g")) <> 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
1570
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. Users have to press a checkbox to specify whether they want to use DataGrid to provide break-up or provide total value in textbox. Now when checkbox is unchecked I am setting the Enabled property of DataGrid to False and vice versa. The problem is...
3
4271
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 several examples on the web. They all seem to have problems, though that I've been unable to resolve. The most promising example I have found is at:
3
3030
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 download a fully working C# sample with the Northwind.mdb here: www.insightgis.com.au/web/stuff/DataGridCombo.zip
2
6414
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
4091
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 tells me if the textbox is readonly or not. I am having a hard time setting the readonly property of the textbox with a conditional if statement (IIF). Here is the coding; <asp:TemplateColumn HeaderText="Data Entry"> <ItemTemplate>
8
1552
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 but one are set as readonly=true. The writeable column does not update when I'm editing it. Is there something different that I need to be doing to update this data? Also, how do I get the "new row" to not appear at the bottom of the datagrid?...
4
1974
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. My problem now is that on ReadOnly cells the shaded background is not at the top of the cell. I adjust the rectangle Height so that the shading does not drop into the next row.
2
3568
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 DataTable("MyTable"); In the classes constructor, after InitializeComponent() I call the following
6
2246
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 Tabbing to get to the desired column but it works fine stopping correctly on the ComboBox column. I have built a routine to test whether the use is Tabbing forward or back (Shift Tab) by looking at the last location, not by trapping the Keys. If
0
9621
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10040
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.