469,888 Members | 1,236 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,888 developers. It's quick & easy.

Datagrid - restrict the user input anything for some columns.

In textbox, I know I can set e.handled = false in keypressevent , So I can
restrict the user to input some invalid character or disallow the user to
input any thing
Now, in datagrid, there are 3 columns one is account code, 2nd is debit, 3rd
is credit
for some account code, (e.g bank) I want to allow the user to input both
debit and credit column/
BUT for some account code( E.g salary) I want to disallow the user type
anything in 'credit' column.

I try edit some code in ProcessCmdKey() , and d/l the some sample code
from http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
But I still fail to restrict the user ,
Does anyone got some idea ?

--
..
Nov 21 '05 #1
3 2331
You could use try this. I did not test it. If you try it, please post
whether it works.

Dim tc() As DataGridTextBoxColumn = {New DataGridTextBoxColumn(), _
New DataGridTextBoxColumn()}
'Set properties of tablecolumns
tc(0).MappingName = "Col1"
tc(0).HeaderText = "Col 1"
tc(0).ReadOnly = True
tc(1).MappingName = "Col2"
'...
Dim ts As New DataGridTableStyle()
ts.GridColumnStyles.AddRange(tc)
Me.DataGrid1.TableStyles.Add(ts)
me.DataGrid1.DataSource = 'datatable or dataview. Fields are mapped
by mapping names. Each mapping name must match a field.

www.charlesfarriersoftware.com

"Agnes" wrote:
In textbox, I know I can set e.handled = false in keypressevent , So I can
restrict the user to input some invalid character or disallow the user to
input any thing
Now, in datagrid, there are 3 columns one is account code, 2nd is debit, 3rd
is credit
for some account code, (e.g bank) I want to allow the user to input both
debit and credit column/
BUT for some account code( E.g salary) I want to disallow the user type
anything in 'credit' column.

I try edit some code in ProcessCmdKey() , and d/l the some sample code
from http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
But I still fail to restrict the user ,
Does anyone got some idea ?

--
..

Nov 21 '05 #2
I know I can use DataGridTableStyle() to set my datagrid but the property
"Read Only" will only make that specified columns is read only. However , my
problem is "case dependent" , If column (1) is "ABC", column2 or column3
can be input.
if column(2) is "XYZ" , column3 can be inputed only. Each row got different
behaviour.
Anyway, I try to seek another solution..
Thanks for your reply
--
..
"Charlie" <Ch*****@discussions.microsoft.com> bl
news:CF**********************************@microsof t.com g...
You could use try this. I did not test it. If you try it, please post
whether it works.

Dim tc() As DataGridTextBoxColumn = {New DataGridTextBoxColumn(), _
New DataGridTextBoxColumn()}
'Set properties of tablecolumns
tc(0).MappingName = "Col1"
tc(0).HeaderText = "Col 1"
tc(0).ReadOnly = True
tc(1).MappingName = "Col2"
'...
Dim ts As New DataGridTableStyle()
ts.GridColumnStyles.AddRange(tc)
Me.DataGrid1.TableStyles.Add(ts)
me.DataGrid1.DataSource = 'datatable or dataview. Fields are mapped by mapping names. Each mapping name must match a field.

www.charlesfarriersoftware.com

"Agnes" wrote:
In textbox, I know I can set e.handled = false in keypressevent , So I can restrict the user to input some invalid character or disallow the user to input any thing
Now, in datagrid, there are 3 columns one is account code, 2nd is debit, 3rd is credit
for some account code, (e.g bank) I want to allow the user to input both
debit and credit column/
BUT for some account code( E.g salary) I want to disallow the user type
anything in 'credit' column.

I try edit some code in ProcessCmdKey() , and d/l the some sample code
from http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
But I still fail to restrict the user ,
Does anyone got some idea ?

--
..

Nov 21 '05 #3
Agnes,
I know I can use DataGridTableStyle() to set my datagrid but the property
"Read Only" will only make that specified columns is read only. However ,
my
problem is "case dependent" , If column (1) is "ABC", column2 or column3
can be input.
if column(2) is "XYZ" , column3 can be inputed only. Each row got
different
behaviour.
Anyway, I try to seek another solution..


I think that that will be in this case the best. You need to control the
input of the datagrid now completly and when a account code column is
changed, you are direct in trouble again when the row is already filled,
(you should have to keep the user on the row until the row is completly
correct).

In this case I think that I would try a texboxes approach above the grid
synchronized using the currencymanager.

Just my thougth,

Cor

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jim Heavey | last post: by
5 posts views Thread by DotNetGruven | last post: by
2 posts views Thread by Daniel Walzenbach | last post: by
2 posts views Thread by Luis Esteban Valencia Muoz | last post: by
reply views Thread by Daniel Doyle | last post: by
9 posts views Thread by BK | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.