datagridview

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cj

    #1

    datagridview

    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.SqlCo nnection
    Dim MySqlCommand As New SqlClient.SqlCo mmand
    Dim MySqlAdapter As New SqlClient.SqlDa taAdapter

    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    MySqlConnection .ConnectionStri ng = "packet size=4096;user ....."
    If ShowPostedToolS tripMenuItem.Ch ecked Then
    MySqlCommand.Co mmandText = "select * from Checks"
    Else
    MySqlCommand.Co mmandText = "select * from Checks where Post
    = 0"
    End If
    MySqlCommand.Co nnection = MySqlConnection


    MySqlAdapter.Se lectCommand = MySqlCommand


    DataGridView1.D ataSource = mydt

    mydt.Clear()
    mydt.Columns.Cl ear()
    Try
    MySqlAdapter.Fi ll(mydt)
    Catch ex As Exception
    MessageBox.Show ("Error: " & ex.Message)
    Exit Sub
    End Try
    End Sub
  • cj

    #2
    Re: datagridview

    Fixed it. I set the datatable columns to readonly before setting
    datagridview1.d atasource = 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.SqlCo nnection
    Dim MySqlCommand As New SqlClient.SqlCo mmand
    Dim MySqlAdapter As New SqlClient.SqlDa taAdapter
    >
    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    MySqlConnection .ConnectionStri ng = "packet size=4096;user ....."
    If ShowPostedToolS tripMenuItem.Ch ecked Then
    MySqlCommand.Co mmandText = "select * from Checks"
    Else
    MySqlCommand.Co mmandText = "select * from Checks where Post
    = 0"
    End If
    MySqlCommand.Co nnection = MySqlConnection
    >
    >
    MySqlAdapter.Se lectCommand = MySqlCommand
    >
    >
    DataGridView1.D ataSource = mydt
    >
    mydt.Clear()
    mydt.Columns.Cl ear()
    Try
    MySqlAdapter.Fi ll(mydt)
    Catch ex As Exception
    MessageBox.Show ("Error: " & ex.Message)
    Exit Sub
    End Try
    End Sub

    Comment

    • zacks@construction-imaging.com

      #3
      Re: datagridview

      On Dec 4, 3:16 pm, cj <c...@nospam.no spamwrote:
      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.SqlCo nnection
      Dim MySqlCommand As New SqlClient.SqlCo mmand
      Dim MySqlAdapter As New SqlClient.SqlDa taAdapter
      >
      Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
      System.EventArg s) Handles MyBase.Load
      MySqlConnection .ConnectionStri ng = "packet size=4096;user ....."
      If ShowPostedToolS tripMenuItem.Ch ecked Then
      MySqlCommand.Co mmandText = "select * from Checks"
      Else
      MySqlCommand.Co mmandText = "select * from Checks where Post
      = 0"
      End If
      MySqlCommand.Co nnection = MySqlConnection
      >
      MySqlAdapter.Se lectCommand = MySqlCommand
      >
      DataGridView1.D ataSource = mydt
      >
      mydt.Clear()
      mydt.Columns.Cl ear()
      Try
      MySqlAdapter.Fi ll(mydt)
      Catch ex As Exception
      MessageBox.Show ("Error: " & ex.Message)
      Exit Sub
      End Try
      End Sub
      Column.ReadOnly property maybe?

      Comment

      Working...