none
Dim cari_Cn As New SqlConnection

    Question

  •  

    Dim cari_Cn As New SqlConnection

    cari_Cn.ConnectionString = "Data Source =192.168.0.2;USer Id = 'SA';password = '';Initial Catalog=" + Label1.Text + ";"

    Dim caribaglan As New SqlConnection(cari_Cn.ConnectionString)

    Dim carisorgu As String = "SELECT CARI_KOD,CARI_ISIM FROM TBLCASABIT ORDER BY CARI_KOD"

    Dim cariverial As New SqlDataAdapter(carisorgu, caribaglan)

    Dim caritablo As New DataTable()

    Dim dataset11 As New DataSet()

    caribaglan.Close()

    cariverial.Fill(caritablo)

    DataGrid1.DataSource = caritablo

    caribaglan.Close()

     

    how can i change datagrid1 collumn's widht

     

    Friday, August 03, 2007 8:43 AM

Answers

  • Your options are a bit limited when using the Datagrid control -- microsoft replaced it with the more robust and functional DatagridView control.  If you can use it then I suggest you start expirementing with the newer control.  But if you have to... 

     

    This is one option with the Datagrid -- set the preferred column width (before yu set the datasource property) and all the columns will be displayed at that width. 

    Code Snippet

    Dim cari_Cn As New SqlConnection

    cari_Cn.ConnectionString = "Data Source =192.168.0.2;USer Id = 'SA';password = '';Initial Catalog=" + Label1.Text + ";"

    Dim caribaglan As New SqlConnection(cari_Cn.ConnectionString)

    Dim carisorgu As String = "SELECT CARI_KOD,CARI_ISIM FROM TBLCASABIT ORDER BY CARI_KOD"

    Dim cariverial As New SqlDataAdapter(carisorgu, caribaglan)

    Dim caritablo As New DataTable()

    Dim dataset11 As New DataSet()

    caribaglan.Close()

    cariverial.Fill(caritablo)

    DataGrid1.PreferredColumnWidth = 200

    DataGrid1.DataSource = caritablo

    caribaglan.Close()

     

     

     You have two columns in your example, so it's unclear if you want both of them to be the same width.

     

    To adjust each column individually you have to access the DatagridColumnStyle object through the DatagridTableStyle's DatagridColumnStylesCollection (phew...  My brain hurts!)  You might be better off learning about it here:

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridcolumnstyle.aspx

     

    Friday, August 03, 2007 12:17 PM