MahamidShaft
New member
- Joined
- Jan 27, 2010
- Messages
- 3
- Programming Experience
- Beginner
Heloo.
I have a few simple questions.
I have a datatable "Voda", which is bind to comboboxcolumn - column1.
When i select some value in this comboboxcolumn, then current cell in column2 need to be populated with apropriate number from datatable "Voda", column "Gostota".
In practise, i'd like to see for example value 992 in propriate row of column2, when selecting "Voda, T=40°C" from comboboxcolumn - column1.
Another question is, how to move some row to the last one in line, if i select some value from comboboxcolumn in the midle of datagridview ?
The last question is, how to delete values in column1 and column2 in some row, when i press delete ?
I don't want to delete row from datatable, only values.
I appreciate some example code.
My code so far.
Tnx.
-------------------------------------------------------------------------------------------------------------------------
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim myConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database\Voda.accdb")
Dim myDataAdapter As OleDbDataAdapter
Dim myDataSet As New DataSet
Dim comboBoxColumn As New DataGridViewComboBoxColumn
Public Sub GetDataFromBase()
myDataAdapter = New OleDbDataAdapter( _
"SELECT Opis, Gostota " & _
"FROM Voda ", myConnection)
myDataAdapter.Fill(myDataSet, "Voda")
myDataAdapter = Nothing
End Sub
Public Sub CreateDataTableandBindItToGrid()
Dim myDataTable As DataTable
myDataTable = New DataTable("Data")
Dim myDataColumn As DataColumn
Dim myDataRow As DataRow
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "Column1"
myDataTable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.Single")
myDataColumn.ColumnName = "Column2"
myDataTable.Columns.Add(myDataColumn)
myDataSet.Tables.Add(myDataTable)
Dim i As Integer
For i = 1 To 10
myDataRow = myDataTable.NewRow
myDataTable.Rows.Add(myDataRow)
Next
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = myDataSet
DataGridView1.DataMember = "Data"
End Sub
Public Sub InsertComboBoxColumnAndBind()
comboBoxColumn.Name = "Column1"
comboBoxColumn.DataPropertyName = "Column1"
comboBoxColumn.Width = "120"
comboBoxColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
comboBoxColumn.DefaultCellStyle.ForeColor = Color.BlueViolet
comboBoxColumn.DefaultCellStyle.BackColor = Color.SeaShell
comboBoxColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
comboBoxColumn.ReadOnly = False
DataGridView1.Columns.Insert(0, comboBoxColumn)
comboBoxColumn.DataSource = myDataSet.Tables("Voda")
comboBoxColumn.DisplayMember = "Opis"
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
GetDataFromBase()
CreateDataTableandBindItToGrid()
InsertComboBoxColumnAndBind()
End Sub
End Class
I have a few simple questions.
I have a datatable "Voda", which is bind to comboboxcolumn - column1.
When i select some value in this comboboxcolumn, then current cell in column2 need to be populated with apropriate number from datatable "Voda", column "Gostota".
In practise, i'd like to see for example value 992 in propriate row of column2, when selecting "Voda, T=40°C" from comboboxcolumn - column1.
Another question is, how to move some row to the last one in line, if i select some value from comboboxcolumn in the midle of datagridview ?
The last question is, how to delete values in column1 and column2 in some row, when i press delete ?
I don't want to delete row from datatable, only values.
I appreciate some example code.
My code so far.
Tnx.
-------------------------------------------------------------------------------------------------------------------------
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim myConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database\Voda.accdb")
Dim myDataAdapter As OleDbDataAdapter
Dim myDataSet As New DataSet
Dim comboBoxColumn As New DataGridViewComboBoxColumn
Public Sub GetDataFromBase()
myDataAdapter = New OleDbDataAdapter( _
"SELECT Opis, Gostota " & _
"FROM Voda ", myConnection)
myDataAdapter.Fill(myDataSet, "Voda")
myDataAdapter = Nothing
End Sub
Public Sub CreateDataTableandBindItToGrid()
Dim myDataTable As DataTable
myDataTable = New DataTable("Data")
Dim myDataColumn As DataColumn
Dim myDataRow As DataRow
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "Column1"
myDataTable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.Single")
myDataColumn.ColumnName = "Column2"
myDataTable.Columns.Add(myDataColumn)
myDataSet.Tables.Add(myDataTable)
Dim i As Integer
For i = 1 To 10
myDataRow = myDataTable.NewRow
myDataTable.Rows.Add(myDataRow)
Next
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = myDataSet
DataGridView1.DataMember = "Data"
End Sub
Public Sub InsertComboBoxColumnAndBind()
comboBoxColumn.Name = "Column1"
comboBoxColumn.DataPropertyName = "Column1"
comboBoxColumn.Width = "120"
comboBoxColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
comboBoxColumn.DefaultCellStyle.ForeColor = Color.BlueViolet
comboBoxColumn.DefaultCellStyle.BackColor = Color.SeaShell
comboBoxColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
comboBoxColumn.ReadOnly = False
DataGridView1.Columns.Insert(0, comboBoxColumn)
comboBoxColumn.DataSource = myDataSet.Tables("Voda")
comboBoxColumn.DisplayMember = "Opis"
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
GetDataFromBase()
CreateDataTableandBindItToGrid()
InsertComboBoxColumnAndBind()
End Sub
End Class