Click to See Complete Forum and Search --> : Datagrid Column Width Problem on Smart Device Application


Ekrcvf
October 4th, 2004, 04:16 AM
Hi,
I am having trouble with adjusting the column width of my datagrid. I ve tried to use table styles but as far as i know i should use table name as the tablestyles mapping name. I can not use it because I receive data from a joined SQL String.
I would appreciate any help...

My Code is below:
Private Sub SoruForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim mydataset As New DataSet
Dim mytable As New DataTable
Dim column1 As New DataColumn("SORU")
mytable.Columns.Add(column1)
Dim column2 As New DataColumn("C")
mytable.Columns.Add(column2)
Dim ts As New DataGridTableStyle
ts.MappingName = "QUESTIONS"

Dim TextCol1 As New DataGridTextBoxColumn
TextCol1.MappingName = "SORU"
TextCol1.HeaderText = "Soru Metni"
TextCol1.Width = 1500
ts.GridColumnStyles.Add(TextCol1)

Dim TextCol2 As New DataGridTextBoxColumn
TextCol2.MappingName = "C"
TextCol2.HeaderText = "Cevap?"
TextCol2.Width = 250
ts.GridColumnStyles.Add(TextCol2)

Sorubox.TableStyles.Clear()
Sorubox.TableStyles.Add(ts)

Dim myrow As DataRow
Dim soruid As String
connection = New SqlCeConnection(connstr)
connection.Open()
Dim command As SqlCeCommand = connection.CreateCommand
command.CommandText = "SELECT SORU_TEXT,SORU_ID FROM QUESTIONS WHERE FORM_ID='" + Degiskenler.Form_id + "'"
Dim reader As SqlCeDataReader = command.ExecuteReader
While reader.Read
If Not reader.IsDBNull(0) Then
myrow = mytable.NewRow
myrow(0) = reader.GetString(0)
End If
If Not reader.IsDBNull(1) Then
soruid = reader.GetString(1)
End If
Dim command2 As SqlCeCommand = connection.CreateCommand
command2.CommandText = "SELECT CEVAP_OK FROM ANSWERS_POCKET WHERE SORU_ID='" + soruid + "'"
Dim reader2 As SqlCeDataReader = command2.ExecuteReader
While reader2.Read
If Not reader2.IsDBNull(0) Then
If reader2.GetString(0) = "C" Then
myrow(1) = "C"
Else
myrow(1) = "?"
End If
End If
End While
mytable.Rows.Add(myrow)
End While

mydataset.Tables.Add(mytable)
Sorubox.DataSource = mydataset.Tables(0)
Sorubox.ColumnHeadersVisible = True
Sorubox.RowHeadersVisible = False

Cursor.Current = Cursors.Default
End Sub