Array declaration and asigning value of array to combobox
-
Hello Experts!! I am declaring one array (having size 10) as an integer and bind array data to grid combobox.It works well but in combobox it shows values as well as zeros....means if array contains 3 values then remaining values shows zero(remaining 7). How to taggle with this? Combo shows like this->1,2,3,0,0,0,0,0,0,0...I dont want that zeros My code is <pre>Dim o As New design Dim i As Integer = 0 Dim rowArray As String() Dim no(10) As Integer //Declaration rssearch = New ADODB.Recordset rssearch.Open("select srno from design", con, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic) While Not rssearch.EOF o = New design o.dsrno = rssearch.Fields("srno").Value Dim row1() As String = {o.dsrno} Dim rows() As Object = {row1} For Each rowArray In rows no(i) = rowArray(0) // Assign value one by one i = i + 1 Next rowArray o = Nothing o = New design rssearch.MoveNext() 'i = i + 1 End While CType(dgvbottom.Columns(8), DataGridViewComboBoxColumn).DataSource = no // Display values in combo
-
Hello Experts!! I am declaring one array (having size 10) as an integer and bind array data to grid combobox.It works well but in combobox it shows values as well as zeros....means if array contains 3 values then remaining values shows zero(remaining 7). How to taggle with this? Combo shows like this->1,2,3,0,0,0,0,0,0,0...I dont want that zeros My code is <pre>Dim o As New design Dim i As Integer = 0 Dim rowArray As String() Dim no(10) As Integer //Declaration rssearch = New ADODB.Recordset rssearch.Open("select srno from design", con, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic) While Not rssearch.EOF o = New design o.dsrno = rssearch.Fields("srno").Value Dim row1() As String = {o.dsrno} Dim rows() As Object = {row1} For Each rowArray In rows no(i) = rowArray(0) // Assign value one by one i = i + 1 Next rowArray o = Nothing o = New design rssearch.MoveNext() 'i = i + 1 End While CType(dgvbottom.Columns(8), DataGridViewComboBoxColumn).DataSource = no // Display values in combo
This is why you should use dynamic lists instead of fixed arrays. The control is doing exactly what you asked it to. Use List<int> instead.
Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
-
Hello Experts!! I am declaring one array (having size 10) as an integer and bind array data to grid combobox.It works well but in combobox it shows values as well as zeros....means if array contains 3 values then remaining values shows zero(remaining 7). How to taggle with this? Combo shows like this->1,2,3,0,0,0,0,0,0,0...I dont want that zeros My code is <pre>Dim o As New design Dim i As Integer = 0 Dim rowArray As String() Dim no(10) As Integer //Declaration rssearch = New ADODB.Recordset rssearch.Open("select srno from design", con, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic) While Not rssearch.EOF o = New design o.dsrno = rssearch.Fields("srno").Value Dim row1() As String = {o.dsrno} Dim rows() As Object = {row1} For Each rowArray In rows no(i) = rowArray(0) // Assign value one by one i = i + 1 Next rowArray o = Nothing o = New design rssearch.MoveNext() 'i = i + 1 End While CType(dgvbottom.Columns(8), DataGridViewComboBoxColumn).DataSource = no // Display values in combo
hi, an int array of dimension 10 always contains 10 numeric values, they get initialized at zero. solutions: 1. give your array the right dimension 2. use a collection instead of an array, say a List Of Int :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
hi, an int array of dimension 10 always contains 10 numeric values, they get initialized at zero. solutions: 1. give your array the right dimension 2. use a collection instead of an array, say a List Of Int :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.