|
-
Jul 31st, 2012, 08:57 AM
#1
Thread Starter
Member
Working with datagridview
Hello,
Trying to figure out a problem just hoping someone might be able to help or point me in the right direction.
What I am trying to do is have a ComboBox's contents and some text boxes be supplied by cells within a datagridview.
What I would like to do is if say column1 contents are = "GY" then that records column2 goes into the comboBox's items. I want it to then loop through the entire datagridview records and add every example of this to the comboBox's collection. From their I want to be able to select a item from the comboBox and then textBox1 and textBox2's contents will be provided from the same record but instead column 3 and 4 of same as the selected item in comboBox... any help would be appreciated. Thanks
-
Jul 31st, 2012, 11:53 AM
#2
Re: Working with datagridview
Can you rephrase the question? As it is right now, I'm having a hard time trying to guess what exactly it is that you want.
Please clearly explain what you want to achieve, post some pictures if need to...
 Originally Posted by jbailey01
Hello,
Trying to figure out a problem just hoping someone might be able to help or point me in the right direction.
What I am trying to do is have a ComboBox's contents and some text boxes be supplied by cells within a datagridview.
What I would like to do is if say column1 contents are = "GY" then that records column2 goes into the comboBox's items. I want it to then loop through the entire datagridview records and add every example of this to the comboBox's collection. From their I want to be able to select a item from the comboBox and then textBox1 and textBox2's contents will be provided from the same record but instead column 3 and 4 of same as the selected item in comboBox... any help would be appreciated. Thanks
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 31st, 2012, 12:45 PM
#3
Lively Member
Re: Working with datagridview
Don't you have an example to show us !!!
-
Jul 31st, 2012, 01:05 PM
#4
Thread Starter
Member
Re: Working with datagridview
Sorry i dont have an example because i dont know how to do this and haven't found anything regarding this in my various searches I have attached pictures

what i want to do exactly is if the first column contains the words TP8 then it looks into the Store Number column... From their i want my drop down box to contain all the different store numbers and use the store number as a record selector so it also bring the city, state, etc. to the textboxes...does this kinda clear it up?
-
Jul 31st, 2012, 03:51 PM
#5
Re: Working with datagridview
That's better but still somewhat unclear. How is the datagridview populated? Is it databound? Where is the combobox? Is it in a different form? How is it populated? Is it databound? If so, what's the datasource?
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 31st, 2012, 04:25 PM
#6
Hyperactive Member
Re: Working with datagridview
I believe what he's wanting to do is something along these lines:
Column A contains a code of some sort. When some unspecified act takes place (clicking on a row, selecting a radio button, hard coded, who knows), the Combobox would be populated with Column B for every row that contains the particular code in Column A. After that, whenever a selection is made in said ComboBox, the values of Columns C & D would be displayed in a pair of TextBoxes.
The only unknown is how the particular code used to populate the ComboBox is selected in the first place. (And also, what the purpose of all of this is because it sounds like it might be simpler to filter the DataGridView.)
-
Jul 31st, 2012, 06:37 PM
#7
Thread Starter
Member
Re: Working with datagridview
The program runs a series of survey's. The datagridview is populated when the user signs in on the login screen that sends them to the welcome screen. I found it easier to do this because the list changes for every user that logs in to show them their corresponding access database. The user will never be able to edit or change their database. It's basically the users daily tasks.
Code:
If txt_Username.Text = reader.Item("username").ToString And txt_Password.Text = reader.Item("password").ToString Then
MessageBox.Show("Login successful")
WelcomeForm.Show()
Me.Hide()
callList = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Jbailey\Documents\CallerLists\" + txt_Username.Text + ".mdb"
Dim connectionString As String = callList
Dim sql As String = "SELECT * FROM CallList"
Dim connection As New OleDbConnection(connectionString)
Dim dataadapter As New OleDbDataAdapter(sql, connection)
Dim ds As New DataSet()
connection.Open()
dataadapter.Fill(ds, "CallList_table")
connection.Close()
WelcomeForm.CallerDataGridView.DataSource = ds
WelcomeForm.CallerDataGridView.DataMember = "CallList_table"
WelcomeForm.CallerDataGridView.Columns(0).Visible = False
WelcomeForm.CallerDataGridView.Columns(1).Visible = True
WelcomeForm.CallerDataGridView.Columns(2).Visible = False
WelcomeForm.CallerDataGridView.Columns(3).Visible = False
WelcomeForm.CallerDataGridView.Columns(4).Visible = False
WelcomeForm.CallerDataGridView.Columns(5).Visible = False
WelcomeForm.CallerDataGridView.Columns(6).Visible = True
WelcomeForm.CallerDataGridView.Columns(7).Visible = False
WelcomeForm.CallerDataGridView.Columns(8).Visible = False
WelcomeForm.CallerDataGridView.Columns(9).Visible = True
WelcomeForm.CallerDataGridView.Columns(10).Visible = False
WelcomeForm.CallerDataGridView.Columns(11).Visible = True
WelcomeForm.CallerDataGridView.Columns(12).Visible = True
WelcomeForm.CallerDataGridView.Columns(13).Visible = False
WelcomeForm.CallerDataGridView.Columns(14).Visible = False
WelcomeForm.CallerDataGridView.Columns(15).Visible = False
If txt_Username.Text = "Jbailey" Then
WelcomeForm.AdministrationToolStripMenuItem.Enabled = True
Else
WelcomeForm.AdministrationToolStripMenuItem.Enabled = False
End If
-
Jul 31st, 2012, 06:41 PM
#8
Thread Starter
Member
Re: Working with datagridview
The form housing the little information I need from the datagridview is exported into another database. The database that I link the grid to changes everyday. So within their tasks on the form that will show the comboBox with the StoreNumber I want it also to show the city, state, and phone number for this. And the ComboBox can only show StoreNumbers that in their Column1 have a certain value for example for this form only stores that have TP8 in the first column will appear in the combobox.. I hope im helping here. Thanks for your guy's time!
-
Aug 1st, 2012, 12:12 PM
#9
Hyperactive Member
Re: Working with datagridview
I still don't understand where you're getting the code from, but to populate the ComboBox, you would do something like this:
vb Code:
Dim i As Integer For i = 0 To DataGridView1.RowCount - 1 If DataGridView1.Rows(i).Cells("WhateverTheCodeColumnIsNamed").Value.ToString = "TP8" Then ComboBox1.Items.Add(DataGridView1.Rows(i).Cells("StoreNumber").Value.ToString) End If Next
And then when a selection is made in the ComboBox you could iterate through the DataGridView again until you find the matching row and then set the value of the two TextBoxes to the value of the corresponding DataGridView cells.
There's probably a better way to do it, but that would work.
Last edited by samuelk; Aug 1st, 2012 at 12:14 PM.
Reason: hard to proofread code while the code box is 1 line high
-
Aug 1st, 2012, 12:47 PM
#10
Thread Starter
Member
Re: Working with datagridview
Thank you i will give it a shot.
-
Aug 1st, 2012, 01:44 PM
#11
Re: Working with datagridview
In regards to your connection to the database, I noticed you have a hard coded path which if running on another PC will fail if the high level folder does not exists as per C:\Users\Jbailey\Documents so if this is the case a better method would be dynamic for the first part of the path as shown below assuming CallerList is under the current user profile My Documents folder.
Code:
Dim Builder As New OleDbConnectionStringBuilder With
{
.DataSource = _
IO.Path.Combine(System.Environment.GetFolderPath(
Environment.SpecialFolder.MyDocuments),
"CallerLists\" & txt_Username.Text & ".mdb"),
.Provider = "Microsoft.Jet.OLEDB.4.0"
}
Dim connection As New OleDbConnection(Builder.ConnectionString)
-
Aug 1st, 2012, 03:11 PM
#12
Thread Starter
Member
Re: Working with datagridview
 Originally Posted by samuelk
I still don't understand where you're getting the code from, but to populate the ComboBox, you would do something like this:
vb Code:
Dim i As Integer For i = 0 To DataGridView1.RowCount - 1 If DataGridView1.Rows(i).Cells("WhateverTheCodeColumnIsNamed").Value.ToString = "TP8" Then ComboBox1.Items.Add(DataGridView1.Rows(i).Cells("StoreNumber").Value.ToString) End If Next
And then when a selection is made in the ComboBox you could iterate through the DataGridView again until you find the matching row and then set the value of the two TextBoxes to the value of the corresponding DataGridView cells.
There's probably a better way to do it, but that would work.
Works like a charm! Thanks. And how would I have the StoreNumber refernced in the ComboBox bring the associated City and State with it?
-
Aug 2nd, 2012, 01:03 PM
#13
Thread Starter
Member
Re: Working with datagridview
Is there any way to use the store number combobox that has been filled as a "row selector" and auto fill the city, state based on the StoreNumber selected?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|