Datagrid - restrict the user input anything for some columns.

A

Agnes

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 ?
 
G

Guest

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
 
A

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..
Thanks for your reply
 
C

Cor Ligthert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top