473,698 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Partially "ReadOnly" windows form datagrid

Hi everyone,

I'm not entirely sure if this is the best way of going about it, but here's
the scenario....... ...

I have two datagrid, each bound to a datatable which have checkbox columns.
There are two buttons between the datagrids, "Add" and "Remove". They
basically remove rows from one grid to the other, only those with the
checkbox ticked.

The problem is I don't want users to add new rows, or alter any of the
columns except for the checkbox column. Is this possible? Or perhaps is
there a better way of selecting multiple rows and working with them? I
realise I have to work with the underlying datasources, *not* the datagrids
themselves, but damn if I know how to go about it.

It's been bugging me all weekend. Any suggestions would be greatly
appreciated.

Cheers,
Dany.
Nov 21 '05 #1
4 2055
> The problem is I don't want users to add new rows, or alter any of the
columns except for the checkbox column. Is this possible?
Create a DataGridTableSt yle set your column to read only

Or perhaps is there a better way of selecting multiple rows and working with them? I
realise I have to work with the underlying datasources, *not* the
datagrids
themselves, but damn if I know how to go about it.

It's been bugging me all weekend. Any suggestions would be greatly
appreciated.

Cheers,
Dany.


Nov 21 '05 #2
Hi,

To prevent the user from adding a new row set the
datatables.defa ultview.allowne w = false.

http://msdn.microsoft.com/library/de...ownewtopic.asp

To make a column readonly set the datagridtextbox column readonly
property to false.

http://msdn.microsoft.com/library/de...donlytopic.asp

Ken
------------------------
"Dany P. Wu" <da**@nospam.qu icksilver.net.n z> wrote in message
news:10******** *******@drone1-svc-skyt.qsi.net.nz ...
Hi everyone,

I'm not entirely sure if this is the best way of going about it, but here's
the scenario....... ...

I have two datagrid, each bound to a datatable which have checkbox columns.
There are two buttons between the datagrids, "Add" and "Remove". They
basically remove rows from one grid to the other, only those with the
checkbox ticked.

The problem is I don't want users to add new rows, or alter any of the
columns except for the checkbox column. Is this possible? Or perhaps is
there a better way of selecting multiple rows and working with them? I
realise I have to work with the underlying datasources, *not* the datagrids
themselves, but damn if I know how to go about it.

It's been bugging me all weekend. Any suggestions would be greatly
appreciated.

Cheers,
Dany.

Nov 21 '05 #3
"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi,
To prevent the user from adding a new row set the
datatables.defa ultview.allowne w = false.
http://msdn.microsoft.com/library/de...n-us/cpref/htm
l/frlrfsystemdata dataviewclassal lownewtopic.asp To make a column
readonly set the datagridtextbox column readonly property to false.
http://msdn.microsoft.com/library/de...n-us/cpref/htm
l/frlrfsystemwind owsformsdatagri dtextboxcolumnc lassreadonlytop ic.asp Ken


Thanks, I've actually done those. I manually added the datagridboolcol umn
and datagridtextbox columns to a newly created tablestyle, each mapped to the
appropriate datatable columns.

I set the textbox columns "readonly=false " and the boolcolumn
"readonly=true" . It worked for the textbox columns - i.e. they are not
editable. Unfortunately it didn't work for the boolcolumn! I could not
change the value of the column. In fact, if I click on it I get an
indexoutofrange exception! The checkbox column is the first one in the
tablestyle.

Any idea why this may be a problem?

Cheers,
D.
Nov 21 '05 #4
Dany,

I did today another sample, so this one was easy to made from it.

\\\Needs only a datagrid on a form
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
DataGrid1.DataS ource = CreateTables()

DirectCast(Data Grid1.DataSourc e, _
DataTable).Defa ultView.AllowNe w = False
Dim dgts As New DataGridTableSt yle
dgts.MappingNam e = "Persons"
Dim textCol As New DataGridTextBox Column
textCol.Mapping Name = "Name"
textCol.HeaderT ext = "Name"
textCol.Width = 200
textCol.ReadOnl y = True
dgts.GridColumn Styles.Add(text Col)
Dim boolCol As New DataGridBoolCol umn
boolCol.Mapping Name = "US"
boolCol.HeaderT ext = "US"
boolCol.Width = 20
boolCol.NullVal ue = False
dgts.GridColumn Styles.Add(bool Col)
DataGrid1.Table Styles.Add(dgts )
End Sub
'Sample datatable
Private Function CreateTables() As DataTable
Dim dtVBReg As New DataTable("Pers ons")
dtVBReg.Columns .Add("Name")
dtVBReg.Columns .Add("US", GetType(System. Boolean))
For i As Integer = 0 To 6
dtVBReg.Rows.Ad d(dtVBReg.NewRo w)
Next
dtVBReg.Rows(0) .ItemArray = New Object() _
{"Herfried K. Wagner", False}
dtVBReg.Rows(1) .ItemArray = New Object() _
{"Ken Tucker", True}
dtVBReg.Rows(2) .ItemArray = New Object() _
{"CJ Taylor", True}
dtVBReg.Rows(3) .ItemArray = New Object() _
{"Jay B Harlow", True}
dtVBReg.Rows(4) .ItemArray = New Object() _
{"Terry Burns", False}
dtVBReg.Rows(5) .ItemArray = New Object() _
{"Tom Shelton", True}
dtVBReg.Rows(6) .ItemArray = New Object() _
{"Cor Ligthert", False}
Return dtVBReg
End Function
////

I hope this helps a little bit?

Cor

"Dany P. Wu" <da**@nospam.qu icksilver.net.n z>
Hi everyone,

I'm not entirely sure if this is the best way of going about it, but
here's the scenario....... ...

I have two datagrid, each bound to a datatable which have checkbox
columns. There are two buttons between the datagrids, "Add" and "Remove".
They basically remove rows from one grid to the other, only those with the
checkbox ticked.

The problem is I don't want users to add new rows, or alter any of the
columns except for the checkbox column. Is this possible? Or perhaps is
there a better way of selecting multiple rows and working with them? I
realise I have to work with the underlying datasources, *not* the
datagrids themselves, but damn if I know how to go about it.

It's been bugging me all weekend. Any suggestions would be greatly
appreciated.

Cheers,
Dany.

Nov 21 '05 #5

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

Similar topics

2
1501
by: G Dean Blake | last post by:
I have a textbox in an ItemTemplate of a grid I'm using to allow users to change a value. I've done it a hundred times. In this project I have it returns the original amount even though the user enters a revised value in the textbox. the code is identical to my many working examples. However, I notice that the xml dataset that the grid is binding from I am using has msdata:ReadOnly="true" generated in it. I can't see how or why that...
5
1587
by: woodpecker | last post by:
when I set the datagrid's readonly=true,I can't set it back to false value,why? Anybody can tell me the reason? Thanks your help. Woodpecker.
1
1228
by: woodpecker | last post by:
when I set readonly=true,I can't set it back to the value "false",why? Anybody can tell me the reason and fix the problem? Thanks advance. Woodpecker.
2
2297
by: Marcin Floryan | last post by:
I am creating a custom control (Inherits UserControl) and my control containt a TextBox control. TextBox control has a Property called "ReadOnly". I would like to expose this property outside my own control, but it seems impossible because when I write: Public Property ReadOnly() as Boolean .... The compilter treats ReadOnly as a Modifier and does not allow this contruct. Can I expose a property of my control under a different name...
2
5236
by: Daren Hawes | last post by:
Hi I need to add an attribute to a Textbox to make it read only. To add a CSS I use DeptDate.Attributes("Class") = "textInput" That adds 'Class="textinput"', but the readonly is like..
3
3187
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something missing from the code? Thanks - Jon Private Sub MakeParentTable() ' Create a new DataTable. Dim myDataTable As Datatable = New Datatable("ParentTable")
5
1536
by: Alex | last post by:
Hello, Is it possible to have a class that has "readonly" properties for some classes and can be written by others? The reason I want this is that some of my classes need to expose their "status", but I need to be ensure that this is only updated by the class that "owns" them, and is not updateable by anything else. Also, I'd rather these classes pass their "status" by reference instead of by value, so any other object querying this...
0
904
by: Li Pang | last post by:
Hi, I populate some data either in a Listview or in a Datagrid, some of data should displayed in readonly mode. I want to know how to partially set these rows in readonly mode. It seems that the readonly property can be only defined at the column level. Thanks in advance
5
4148
by: elainenguyen | last post by:
Hi, since assigned "acFormReadOnly", my code supposes to allow user to only "read the form", but when I test the code, I can type and click on any of the fields on the form. What I really want the code to do is not allow user to be able to click or type on any of the fields, on the form. Any idea? please help. Dim db As Database Dim rst As Recordset Dim stLinkCriteria As String Set db = CurrentDb Set rst =...
0
8674
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...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9026
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
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
7723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
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
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
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.