|
Yes, I see that now...for similar reasons why the forum post is being down voted as well.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Here is a function to populate any combobox with data from a table column.This style wld work for any database. I prefer to use oracle in this instance.
You first have to create the function in a module or class
and call it from anywhere in your project with the required parameters
<br />
<br />
'For instance, drop a combobox(combobox1) and a button(button1) and under the button add<br />
<br />
Private Sub Button1_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles Button1.Click<br />
<br />
'when calling from a class <br />
'className.populateAnyCombo(comboboxName,"sql statment", _ <br />
'column name, connection string)<br />
<br />
'---call function from a module----<br />
<br />
PopulateAnyCombo(combobox1,"SQL(eg Select Column_Name from Table_Name)", _<br />
"column_name", connectionString)<br />
<br />
End Sub<br />
<br />
<br />
<br />
<br />
<br />
'----------Place in a module or class----------<br />
<br />
Public Function PopulateAnyCombo(ByVal cBox As ComboBox, ByVal strSQL _<br />
As String, ByVal tableColumn As String,ByVal connString As String ) As String()<br />
<br />
Dim array(0) As String<br />
Dim cnt As Integer = 0<br />
Dim conn As New OracleConnection<br />
<br />
conn.ConnectionString = connString<br />
Try<br />
conn.Open()<br />
Catch ex As Exception<br />
MsgBox("Failed conection to Oracle" & ex.Message)<br />
Return array<br />
End Try<br />
<br />
Dim cmd As New OracleCommand<br />
With cmd<br />
.CommandText = strSQL<br />
.CommandType = CommandType.Text<br />
.Connection = conn<br />
End With<br />
'data reader to store recordsets retrieved<br />
Dim dr As OracleDataReader<br />
<br />
'Reading an populating records in array<br />
'ReDim preserve increases the array size and preserve old members<br />
Try<br />
dr = cmd.ExecuteReader<br />
While dr.Read<br />
ReDim Preserve array(cnt)<br />
array(cnt) = dr.Item(tableColumn)<br />
cnt = cnt + 1<br />
End While<br />
<br />
cBox.Items.Clear()<br />
cBox.Items.AddRange(array)<br />
<br />
Return array<br />
Catch ex As Exception<br />
<br />
Dim a(0) As String<br />
a(0) = 0<br />
Return a<br />
Finally<br />
conn.Close()<br />
conn.Dispose()<br />
End Try<br />
End Function<br />
<br />
'-----------------place in a module or class-------------<br />
<br />
Would be glad to know if i helped solve a problem
Criticisms to this snippet are welcomed
nan492001@yahoo.com
|
|
|
|
|
What is this?
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
जय हिंद
|
|
|
|
|
He's trying to promote his article that is getting rejected.
"Well, we're getting "F"'d at work. WPF, WCF, and WWF... WTF?" --John Simmons
|
|
|
|
|
Everytime I change something in the dropdown list, the page doesn't change, it just stays the same, What problems could I have.
|
|
|
|
|
This sounds like it's an asp.net related question, so it should probably be asked in that forum[^]. No matter what, you need to provide more explanation of what you are trying to accomplish, what your code looks like, etc. This isn't really enough information for someone to try and help.
Simple questions first:
1. What event are you listening for? (From the title it sounds like the SelectedIndexChanged event.)
2. Do you have the handler wired correctly? (Can you set a break point in the event handler and see that it gets hit?)
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
well this my code behind
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
'Dim ds As DataTable
'ds = GridView1.DataSource
'GridView1.DataSource = ds
PopulateGrid(Convert.ToDateTime(DropDownList1.SelectedValue.ToString()))
|
|
|
|
|
This message has been "moved[^]" to the ASP.NET forum.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Hello
I am using on-demand subreport in crystal report for the first time. Please help me on following problems.
1)I dont know exactly on which event to set datasource for on-demand subreport & how to set datasource for on-demand subreport.
2)How to get main report value against which I want to load subreport.
Regards
Ali Raza
|
|
|
|
|
Hai,
I did socket server application using VB.NET, it will receive every minutes 100000 of data for my IP it contains around forty coma separated values. Once if receive the data i need to store in sql Server, wats the best way to handle this kind of situation for the best better performance.
|
|
|
|
|
srisant wrote: wats the best way to handle this kind of situation for the best better performance.
Use asynchronous fashioned methods. Separate the socket data receive and processing into multiple threads so that none of them will be blocked.
|
|
|
|
|
Adding to what has been said, you can use ThreadPool to take care of this.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Well, Asynchronous methods uses a thread pool thread internally.
|
|
|
|
|
Hi,
I want to integrate vb in the mainframe environment. As in some mainframe emulators gui feauters like mouse scroll up and down are restricted. can you please help me how to do this through vb
|
|
|
|
|
Its doubtful that you will get a vb.net app to run on a mainframe as it will require the .net runtime.
ushaallwyn wrote: mouse scroll up and down are restricted. can you please help me how to do this through vb
If this typical of your level of experience I suggest you start with something easier than a mainframe emulator.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
This question doesn't make sense at all. I appears as though you wnat to run VB code on the mainframe. That's never going to happen.
Now, you can write a terminal emulator that connects to a mainframe, but, I suspect that such a complex project is beyond your current abilities. In the terminal app, the only thing the scroll wheel would be good for would be to scroll the terminal window's text up and down. You usually don't see that kind of functionality because most terminal windows are of a fixed size and mainframe applications know this and don't provide scrolling information.
|
|
|
|
|
Hello,
I have a datagridview it contains 3 comboboxes, when combo1(category) is selected, the combo2(sub-Category) will display, when the combo2(sub-Category) is selected combo3(price) will display. every thing is working fine for the first row. when i do same thing in the second row the combo2 contains the previous sub-category and combo3 contains previous price how to restrict it.
please go throught the code if something is missing
code:
Public ddlCategory As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn()
Public ddlSubCategory As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn()
Public ddlPrice As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn()
-----------------------------------------------------------------
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ddlCategory.Name = "Category"
ddlSubCategory.Name = "SubCategory"
ddlPrice.Name = "Price"
DataGridView1.Columns.Insert(0, ddlCategory)
DataGridView1.Columns.Insert(1, ddlSubCategory)
DataGridView1.Columns.Insert(2, ddlPrice)
Dim scmd As String = "select distinct Category from master"
Dim sqlda As New SqlDataAdapter(scmd, strCon)
sqlda.Fill(DS, "ProjNo")
ddlCategory.DataSource = DS.Tables("Category")
ddlCategory.DisplayMember = "Category"
ddlCategory.ValueMember = "Category"
sqlda.Dispose()
sqlda = Nothing
DataGridView1.Rows.Add(3)
End Sub
------------------------------------------------------------------------
Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
cb = TryCast(e.Control, ComboBox)
If cb IsNot Nothing Then
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVddlCategoryComboIndexChanged
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVddlSubCategoryComboIndexChanged
Select Case gvMultipleProjects.CurrentCell.ColumnIndex
Case 0
AddHandler cb.SelectedIndexChanged, AddressOf DGVddlCategoryComboIndexChanged
Case 1
AddHandler cb.SelectedIndexChanged, AddressOf DGVddlSubCategoryComboIndexChanged
End Select
End If
End Sub
----------------------------------------------------------------------
Private Sub DGVddlddlCategoryComboIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim com As ComboBox = CType(sender, ComboBox)
Dim scmd As String = "select distinct SubCategory from master where Category='" & com.SelectedItem.ToString() & "'"
Dim sqlda As New SqlDataAdapter(scmd, strCon)
sqlda.Fill(DS, "ProjNo")
ddlSubCategory.DataSource = DS.Tables("SubCategory")
ddlSubCategory.DisplayMember = "SubCategory"
ddlSubCategory.ValueMember = "SubCategory"
sqlda.Dispose()
sqlda = Nothing
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVddlCategoryComboIndexChanged
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVddlProjNoComboIndexChanged
End Sub
----------------------------------------------------------------
Private Sub DGVddlSubCategoryComboIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim com As ComboBox = CType(sender, ComboBox)
Dim scmd As String = "select price from master where SubCategory=" & com.SelectedValue.ToString() & ""
Dim sqlda As New SqlDataAdapter(scmd, strCon)
sqlda.Fill(DS, "Price")
ddlPrice.DataSource = DS.Tables("Price")
ddlPrice.DisplayMember = "Price"
ddlPrice.ValueMember = "id"
sqlda.Dispose()
sqlda = Nothing
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVddlCategoryComboIndexChanged
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVddlSubCategoryComboIndexChanged
End Sub
Thanks in advance
saha
|
|
|
|
|
As far as I can tell, you're reusing the exact same cb editing control. It's just being move from one cell to the next, so, of course, it's going to have the previous values that were entered. Either destroy the existing combo and create a new one, or clear whatever properties you need to from the existing one, depending on your requirements.
|
|
|
|
|
Hello Dave,
Can you give me some idea how to do that, i have used the cb.Refresh(), cb.ResetText(), it is not working if i use cb.dispose() it is throwing error "Cannot access disposed".
please let me know if i have done some mistake.
Thanks&Regards
saha.
|
|
|
|
|
please go through the code
|
|
|
|
|
please go through the code little urgent
|
|
|
|
|
I have same problem. can you give me some hint, I have tried using different CB but it didn't work for me.
Thanks & Regards
Sandip Khillare
Web Developer
Enrich Web Technologies
modified on Saturday, February 14, 2009 5:40 AM
|
|
|
|
|
you just add this code to clear the comboBox
ddlCategory.DataSource = null;
then write code to list subcategory under the ddlCategory ValueChanged event
|
|
|
|
|
mates,
how to play a sound in visual basic 6.0?
it will play the sound when the form is load. it will only stop
when i click a specific button. how will i do that?
thanks in advance.
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
There is a windows media player control available. Use that and load a sound file.
|
|
|
|