PC Review


Reply
Thread Tools Rate Thread

Datagrid, disable the cell programically

 
 
Agnes
Guest
Posts: n/a
 
      22nd Nov 2004
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)

--
..


 
Reply With Quote
 
 
 
 
Lucas Tam
Guest
Posts: n/a
 
      22nd Nov 2004
"Agnes" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> 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 ((E-Mail Removed))
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
 
Reply With Quote
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      22nd Nov 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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)

--
..



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable a specified datagrid cell Greg Microsoft C# .NET 0 11th May 2006 03:23 PM
Disable Datagrid Cell Based On Initial Value mkrei@yahoo.com Microsoft VB .NET 1 18th Jan 2006 02:11 AM
Programically update a colum in a datagrid =?Utf-8?B?Smlt?= Microsoft VB .NET 3 19th Sep 2005 07:55 PM
How do you programically remove carriage returns within a cell =?Utf-8?B?TGVl?= Microsoft Excel Programming 2 20th Jul 2005 06:43 PM
Can't format datagrid programically =?Utf-8?B?bWlrZQ==?= Microsoft VB .NET 9 9th Mar 2004 04:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:00 AM.