Datagridview

R

Robert

Using VB.Net 2008

I have this code in a form, to create the cells on my datagridview.
Depending on the users selection, the grid is created.

This sample is for the Creditors.

Snipett:
The following works and populates the combo box, and the text boxes.
Need to find the ID value to enter it in the txtgrFixedID field once an
asset
is selected.


Try
With frmMain.grdSelections

..Columns.Clear()

'The commented code works to add a combo to the grid.

Dim txtgrFixedID As New DataGridViewTextBoxColumn

Dim colgrExpress As New DataGridViewComboBoxColumn

Dim txtgrMnthly As New DataGridViewTextBoxColumn

Dim txtgrYearly As New DataGridViewTextBoxColumn

txtgrFixedID.Name = "AssetsID"

With colgrExpress

'.Name = "Select a Variable Expense"

..HeaderText = "Select an Asset"

..ReadOnly = False

..AutoComplete = True

..DropDownWidth = 250

End With

With txtgrMnthly

..Name = "Value of Asset"

..DefaultCellStyle.NullValue = FormatNumber("0.00")

..ReadOnly = False

End With

With txtgrYearly

..Name = "Maturity Date"

..DefaultCellStyle.NullValue = Format(Now(), "MMM dd, yyyy")

..ReadOnly = True

End With

'Open the connection.

con.Open()

Dim rea As OleDbDataReader

Dim cmd As New OleDb.OleDbCommand("SELECT * FROM AssetsItems", con)

rea = cmd.ExecuteReader

colgrExpress.Items.Clear()

'Load the DataGridView.

While rea.Read()

colgrExpress.Items.Add(rea("NAssets"))

colgrExpress.DisplayMember = "NAssets"

colgrExpress.ValueMember = "AssetsID"

End While

'Close the connection.

con.Close()

..Columns.Add(txtgrFixedID)

..Columns.Add(colgrExpress)

..Columns.Add(txtgrMnthly)

..Columns.Add(txtgrYearly)

..Columns(0).Width = 0

..Columns(1).Width = 150

..Columns(2).Width = 100

etc.

I was able to use the ItemData in VB6.

I need to be able to fnd the AssetsID when user selects a value from the
combo box.

Any tips on how to get this.

Was so easy in VB6
 
C

Cor Ligthert

You asked for a tip.

Don't try to use the controls in Net as MSFlexGrid controls in VB6 in fact
don't try to do anything what was not easy (Something can be easy for you,
because you are used to it. Driving a car with a handgear is not easy, until
you are used then it, then you think how could it be done better in another
way)

To act with data in data in .Net use the datasources. One way to find the
current possition is the currencymanager (not the best chosen name as most
people start to think it has to do with money)

http://msdn.microsoft.com/en-us/library/system.windows.forms.currencymanager.aspx

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top