7 Replies - 469 Views - Last Post: 21 January 2014 - 12:09 AM Rate Topic: -----

#1 langga1235  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 14

Column's data in datagrid

Posted 16 January 2014 - 07:00 AM

Hello, I'm just new in VB.net after switching learning the basics in C
well my problem is I want a specific column that is editable .

ID Name LastName
1 N1 L1
2 N2 L3
3 N3 L4
4 N4 L5


I want to edit the data in ID column like I can edit 1 to 11 , 1111,etc while the rest of the columns is not editable

Actually I don't know where to start. Is there any functions that I should make?. Any help would be appreciated :)/> anyway thank you

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="Your .mdb path";"
        Dim sql As String = "SELECT * FROM Employee"
        Dim connection As New OleDbConnection(connectionString)
        Dim dataadapter As New OleDbDataAdapter(sql, connection)
        Dim ds As New DataSet()
        connection.Open()
         da.Fill(ds)
        connection.Close()
        DataGridView1.DataSource = ds

       DataGridView1.Columns(0).HeaderText="ID"
       DataGridView1.Columns(0).HeaderText="Name"
       DataGridView1.Columns(0).HeaderText="Last Name"
       
    End Sub




Is This A Good Question/Topic? 0
  • +

Replies To: Column's data in datagrid

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: Column's data in datagrid

Posted 16 January 2014 - 08:02 AM

12	     DataGridView1.Columns(0).HeaderText="ID"
13	     DataGridView1.Columns(0).HeaderText="Name"
14	     DataGridView1.Columns(0).HeaderText="Last Name"

Any particular reason why you are setting the first column's header text to three different things?


Also - in the column object - is a 'readonly' flag.. if you set that to 'false' then the column is not editable.
Was This Post Helpful? 0
  • +
  • -

#3 langga1235  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 14

Re: Column's data in datagrid

Posted 16 January 2014 - 07:03 PM

ops sorry i for got to change the header text

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  

02       Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="Your .mdb path";" 

03       Dim sql As String = "SELECT * FROM Employee" 

04       Dim connection As New OleDbConnection(connectionString)  

05       Dim dataadapter As New OleDbDataAdapter(sql, connection)  

06       Dim ds As New DataSet()  

07       connection.Open()  

08        da.Fill(ds)  

09       connection.Close()  

10       DataGridView1.DataSource = ds  

11   

12      DataGridView1.Columns(0).HeaderText="ID" 

13      DataGridView1.Columns(1).HeaderText="Name" 

14      DataGridView1.Columns(2).HeaderText="Last Name" 

15         

16   End Sub 




should i put

[code]
DataGridView1.Columns(0).ReadOnly=false;
[code]

any idea?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: Column's data in datagrid

Posted 16 January 2014 - 07:05 PM

I thought I was clear on that - yes.. read only will set it so the column cannot be editable.
Was This Post Helpful? 0
  • +
  • -

#5 langga1235  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 14

Re: Column's data in datagrid

Posted 16 January 2014 - 07:49 PM

i tried to insert that code but its not working..any idea? thank you
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: Column's data in datagrid

Posted 16 January 2014 - 07:50 PM

There could be a million things wrong.. how about you be more specific on what it is doing, what your code looks like, and what you were expecting.
Was This Post Helpful? 0
  • +
  • -

#7 langga1235  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 14

Re: Column's data in datagrid

Posted 16 January 2014 - 07:54 PM

i change the grid in editonkeystroke then change the other column to readonly to true well its working anyway thank you
Was This Post Helpful? 0
  • +
  • -

#8 langga1235  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 14

Re: Column's data in datagrid

Posted 21 January 2014 - 12:09 AM

hello I have this new problem about autosizing the grid

I want to autosize the cells based from its data

dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells



well it works find but the problem is want rezize again the column because some headertext is not in good shame

for example

Column1 Col
umn2
123456 123

as you can see the column2 is not in good shape , I inserted column.width(2)=100 after the autosizemode but its not working , anyone have a suggestion?

shape* typo sorry

shape* typo sorry
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1