473,320 Members | 1,848 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,320 software developers and data experts.

Datagrid, disable the cell programically

In myDatagrid, there is 3 columns, account code, debit,credit.
If the user input some particular a account code in column1 , i need to
based on the contect of column1, to disable column2(debit),column3(credit)
I try processcmdkey , onKeypress, onKeydown event already ( set e.handled =
false , just like textbox event)
However, it still let the user input anyfield ( after use press'tab', the
field will gone blank)
My aim is, user press any key, the column should shown nothing .
I try the keypress event in Textbox, (it is sucessful, but I am fail in
Datagrid)

--
..
Nov 21 '05 #1
2 5007
"Agnes" <ag***@dynamictech.com.hk> wrote in
news:uL**************@tk2msftngp13.phx.gbl:
In myDatagrid, there is 3 columns, account code, debit,credit.
If the user input some particular a account code in column1 , i need
to based on the contect of column1, to disable
column2(debit),column3(credit) I try processcmdkey , onKeypress,
onKeydown event already ( set e.handled = false , just like textbox
event) However, it still let the user input anyfield ( after use
press'tab', the field will gone blank)
My aim is, user press any key, the column should shown nothing .
I try the keypress event in Textbox, (it is sucessful, but I am fail
in Datagrid)

There should be a solution for your problem here... If not, you may need to
mix and match solutions:

http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #2
Hi,

You have to make your own datagrid column style to do that. Here is
a simple example. You need a datagrid1 on a form. This will only allow you
to edit the name of product in the northwind database if it isnt
discontinued.

Imports System.Data.SqlClient

Public Class Form1

Inherits System.Windows.Forms.Form

Dim ds As New DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim conn As SqlConnection

Dim strConn As String

Dim strSQL As String

Dim da As SqlDataAdapter

'strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

'strConn &= "Data Source = Northwind.mdb;"

strConn = "Server = (local);"

strConn &= "Database = NorthWind;"

strConn &= "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)

da = New SqlDataAdapter("Select * From Products", conn)

da.Fill(ds, "Products")

Dim ts As New DataGridTableStyle

ts.MappingName = ds.Tables("Products").TableName

Dim colDiscontinued As New DataGridBoolColumn

With colDiscontinued

..MappingName = "Discontinued"

..HeaderText = "Discontinued"

..Width = 80

End With

Dim colName As New EditSomeTimes

With colName

..MappingName = "ProductName"

..HeaderText = "Product Name"

..Width = 180

End With

ts.GridColumnStyles.Add(colName)

ts.GridColumnStyles.Add(colDiscontinued)

DataGrid1.TableStyles.Add(ts)

DataGrid1.DataSource = ds.Tables("Products")

ts = Nothing

colDiscontinued = Nothing

colName = Nothing

End Sub

End Class

Public Class EditSomeTimes

Inherits DataGridTextBoxColumn

Protected Overloads Overrides Sub Edit(ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds
As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText
As String, ByVal cellIsVisible As Boolean)

Dim dt As DataTable

Try

dt = CType(Me.DataGridTableStyle.DataGrid.DataSource, DataTable)

Dim dr As DataRow

dr = dt.Rows.Item(source.Position)

If Not CBool(dr.Item("Discontinued")) Then

MyBase.Edit(source, rowNum, bounds, [readOnly], instantText, cellIsVisible)

End If

Catch ex As Exception

End Try

End Sub

End Class

Ken

-----------------------

"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:uL**************@tk2msftngp13.phx.gbl...
In myDatagrid, there is 3 columns, account code, debit,credit.
If the user input some particular a account code in column1 , i need to
based on the contect of column1, to disable column2(debit),column3(credit)
I try processcmdkey , onKeypress, onKeydown event already ( set e.handled =
false , just like textbox event)
However, it still let the user input anyfield ( after use press'tab', the
field will gone blank)
My aim is, user press any key, the column should shown nothing .
I try the keypress event in Textbox, (it is sucessful, but I am fail in
Datagrid)

--
..

Nov 21 '05 #3

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

Similar topics

0
by: JP011 | last post by:
Hello I have hit a major road block when it comes to building my dynamic datagrid. To make a long story short I need a dynamic datagrid because my connection string could change and I need the...
4
by: Terry | last post by:
Hey, Having somewhat of an issue, I have a datagrid which is giving me issues. The Datagrid is setup for the user to double click the row, the row is selected and data within that row populates a...
1
by: PawelR | last post by:
Hello group, In my application, I have form with DataGrid. Rows in dataGrid are from table. myDG.DataSource = myTable; In Table I have collumn boolean type. On Click (Mouse_up event) on...
2
by: news | last post by:
Hello All, As a VB6/C/C++ (and some Java) developer, I've been toying with c# for the last couple of weeks. I'm currently trying to create a grid of 3x3 with each cell containing numbers from 1...
3
by: Jim | last post by:
I have a datagrid with a DataAdapter as the DataSource. The user fills in their data for 3 columns and I want to programically add a value to the 4th (invisible) column (employee number). That way...
1
by: mkrei | last post by:
I have datagrid that I format at runtime with tablestyles and adding columns. I have a DataGridBoolColumn that I have subclassed, but can't get the right result. I want to disable a cell based on...
5
by: Sharon | last post by:
I have a DataGrid on my Form, and I wish to disable any cell editing. For example; when the user clicks on a cell, the cell become editable by changing its color to gray and context menu is shown...
0
by: Greg | last post by:
Given x,y coordinates for a datagrid cell, how do I disable the cell (not the whole column)?
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.