473,399 Members | 3,919 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,399 software developers and data experts.

datagridview

cj
I need to make all but 2 of the columns in the datagridview readonly.
Can I do this? How? Below is my code.

Dim MySqlConnection As New SqlClient.SqlConnection
Dim MySqlCommand As New SqlClient.SqlCommand
Dim MySqlAdapter As New SqlClient.SqlDataAdapter

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
MySqlConnection.ConnectionString = "packet size=4096;user ....."
If ShowPostedToolStripMenuItem.Checked Then
MySqlCommand.CommandText = "select * from Checks"
Else
MySqlCommand.CommandText = "select * from Checks where Post
= 0"
End If
MySqlCommand.Connection = MySqlConnection
MySqlAdapter.SelectCommand = MySqlCommand
DataGridView1.DataSource = mydt

mydt.Clear()
mydt.Columns.Clear()
Try
MySqlAdapter.Fill(mydt)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
Exit Sub
End Try
End Sub
Dec 4 '07 #1
2 2722
cj
Fixed it. I set the datatable columns to readonly before setting
datagridview1.datasource = mydt.

This way the datagridview seemed to know those columns were readonly.

Sometimes all I have to do is ask to figure out something.

cj wrote:
I need to make all but 2 of the columns in the datagridview readonly.
Can I do this? How? Below is my code.

Dim MySqlConnection As New SqlClient.SqlConnection
Dim MySqlCommand As New SqlClient.SqlCommand
Dim MySqlAdapter As New SqlClient.SqlDataAdapter

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
MySqlConnection.ConnectionString = "packet size=4096;user ....."
If ShowPostedToolStripMenuItem.Checked Then
MySqlCommand.CommandText = "select * from Checks"
Else
MySqlCommand.CommandText = "select * from Checks where Post
= 0"
End If
MySqlCommand.Connection = MySqlConnection
MySqlAdapter.SelectCommand = MySqlCommand
DataGridView1.DataSource = mydt

mydt.Clear()
mydt.Columns.Clear()
Try
MySqlAdapter.Fill(mydt)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
Exit Sub
End Try
End Sub
Dec 4 '07 #2
On Dec 4, 3:16 pm, cj <c...@nospam.nospamwrote:
I need to make all but 2 of the columns in the datagridview readonly.
Can I do this? How? Below is my code.

Dim MySqlConnection As New SqlClient.SqlConnection
Dim MySqlCommand As New SqlClient.SqlCommand
Dim MySqlAdapter As New SqlClient.SqlDataAdapter

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
MySqlConnection.ConnectionString = "packet size=4096;user ....."
If ShowPostedToolStripMenuItem.Checked Then
MySqlCommand.CommandText = "select * from Checks"
Else
MySqlCommand.CommandText = "select * from Checks where Post
= 0"
End If
MySqlCommand.Connection = MySqlConnection

MySqlAdapter.SelectCommand = MySqlCommand

DataGridView1.DataSource = mydt

mydt.Clear()
mydt.Columns.Clear()
Try
MySqlAdapter.Fill(mydt)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
Exit Sub
End Try
End Sub
Column.ReadOnly property maybe?
Dec 4 '07 #3

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

Similar topics

0
by: DraguVaso | last post by:
Hi, I'm using the DataGridView in VB.NET 2.0. The DataSource is a Generic List of a custom class0: lstMyPersonnes = New List(Of clsPersonne). When I add a new clsPersonne to lstMyPersonnes,...
6
by: dbuchanan | last post by:
Hello, Is this a bug? Is there some kind of work around? I want to add default values for a few columns in my datagridview I found the "DefaultValuesNeeded" event for the datagridview I...
10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
0
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.