473,789 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5043
"Agnes" <ag***@dynamict ech.com.hk> wrote in
news:uL******** ******@tk2msftn gp13.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********@rog ers.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.Sql Client

Public Class Form1

Inherits System.Windows. Forms.Form

Dim ds As New DataSet

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Dim conn As SqlConnection

Dim strConn As String

Dim strSQL As String

Dim da As SqlDataAdapter

'strConn = "Provider = Microsoft.Jet.O LEDB.4.0;"

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

strConn = "Server = (local);"

strConn &= "Database = NorthWind;"

strConn &= "Integrated Security = SSPI;"

conn = New SqlConnection(s trConn)

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

da.Fill(ds, "Products")

Dim ts As New DataGridTableSt yle

ts.MappingName = ds.Tables("Prod ucts").TableNam e

Dim colDiscontinued As New DataGridBoolCol umn

With colDiscontinued

..MappingName = "Discontinu ed"

..HeaderText = "Discontinu ed"

..Width = 80

End With

Dim colName As New EditSomeTimes

With colName

..MappingName = "ProductNam e"

..HeaderText = "Product Name"

..Width = 180

End With

ts.GridColumnSt yles.Add(colNam e)

ts.GridColumnSt yles.Add(colDis continued)

DataGrid1.Table Styles.Add(ts)

DataGrid1.DataS ource = ds.Tables("Prod ucts")

ts = Nothing

colDiscontinued = Nothing

colName = Nothing

End Sub

End Class

Public Class EditSomeTimes

Inherits DataGridTextBox Column

Protected Overloads Overrides Sub Edit(ByVal source As
System.Windows. Forms.CurrencyM anager, 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.DataGr idTableStyle.Da taGrid.DataSour ce, DataTable)

Dim dr As DataRow

dr = dt.Rows.Item(so urce.Position)

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

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

End If

Catch ex As Exception

End Try

End Sub

End Class

Ken

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

"Agnes" <ag***@dynamict ech.com.hk> wrote in message
news:uL******** ******@tk2msftn gp13.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
1352
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 datagrid to handle that. First I tried to create my datagrid by leaving the auto-generate columns equal to true. This worked fine except that when my user wants to edit a line I do not want them to edit column 1, only column 2. I could not find a...
4
15470
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 form for editing. the problem is when a user clicks on a cell instead of the whole row, I get an error. My question is this, is there anyway I can setup the datagrid so when the user clicks on any cell, the whole row is selected not just that...
1
4499
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 the dataGrid I change value in this column
2
1605
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 to 9. The idea is that if you push one of the numbers, it gets 'blown up' to the full size of the control, hiding all the other ones. It should also be possible to enable/disable some cells in the grid through calling a method. I've actually...
3
1812
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 when the user saves the data I can use the data already in the datagrid. Typically the user will add several rows before the DataSet.HasChanges is called and the DataAdapter.Update(AllChanges) is called. I want to add an employee number to each...
1
1813
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 the initial value of that checkbox. If the initial value is checked, I want it to be disable where the user can't change it. If the intial value is not checked, then the user can select and deselect the checkbox. When the datagrid is first...
5
4437
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 on muse right mouse click. I do not want the enable this cell context menu (I have my own context menu) and I do not want the cell to change it's color. I want that on any click - the entire row will be selected. There are some other cases where...
0
920
by: Greg | last post by:
Given x,y coordinates for a datagrid cell, how do I disable the cell (not the whole column)?
7
3228
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 column need to be a date picker field. I know things will be easier with ASPX datagrid.
0
9663
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
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10195
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
9016
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
6765
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
5415
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...
1
4090
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
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
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.