Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / March 2005

Tip: Looking for answers? Try searching our database.

Datagrids - Rows???

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Darryn Ross - 23 Mar 2005 02:35 GMT
Hi

How do i set a row readonly after applying custom table styles and binding
to a datasource??

i need to set particular rows readonly, but i do not know what they are
until i have loaded data from my tables.

Regards

Darryn
Erwin Pant - 23 Mar 2005 14:16 GMT
Hi,

As far as I know, you can only set columns or the entire datagrid read-
only.  What I suggest is that in your table (in the database), you have a
column "ReadOnly" for example and you set it for the rows you want.  When a
user tries to modify a particular row, you do a lookup on that column in
your dataset in the CurrentCellChanged event of your DataGrid.

Hope this helps,

E
Darryn Ross - 23 Mar 2005 23:25 GMT
ok... does really help my case at all.

one other thing i could try to do is, check for a setting in the
CurrentCellChanged event to see wether it is a row i should be changing or
and if it isn't deny the change??

i am not sure how to do this though?

> Hi,
>
[quoted text clipped - 7 lines]
>
> E
Erwin Pant - 24 Mar 2005 18:55 GMT
Why don't you want to add a ReadOnly column to your table.  Here's an
example that I tested and works:

In your Database:
-----------------
- I have a table tblNames with ID, FirstName and LastName
- Add a ReadOnly column of type Bit (assuming you're using SQL Server)
- Update all rows that you want flagged as "ReadOnly"

You should get the results (for example):

ID   FirstName   LastName    ReadOnly
---- ----------- ----------- --------
1    Joe         Shmoe       0
2    John        Doe         1
3    Jane        Doe         1
4    Homer       Simpson     0

In your program:
----------------
- Add a DataGrid
- Add your table styles
- Add the following code:

Imports System.Data.SqlClient

Public Class Form1
   Inherits System.Windows.Forms.Form

   Private strCnn As String = "integrated security=SSPI;data source=" +
{Place your data source here} + ";persist security info=False;initial
catalog=" + {Place your database here}"
   Dim sqlCn As SqlConnection = New SqlConnection(strCnn)
   Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM tblNames",
sqlCn)
   Dim ds As New DataSet

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

       sqlCn.Open()
       da.Fill(ds, "Names")
       sqlCn.Close()
       DataGrid1.DataSource = ds

   End Sub

   Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
       DataGrid1.ReadOnly = ds.Tables(0).Rows
(DataGrid1.CurrentCell.RowNumber).Item("ReadOnly") = True
   End Sub
End Class

** In the code, when the CurrentCellChange event is triggered, I am
checking the ReadOnly column of the dataset.  If it is true, then I make
the ENTIRE GRID read-only.  When I change to a row where ReadOnly is false,
I set the grid's ReadOnly property to false.

It's quick and it's simple !

Cheers !

E

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.