|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataGridView and ComboBoxForgive me for posting this message in 2 groups -- it appears that the Data Access group isn't very active, so I'm posting again here: I have a DataTable that I want to fill using a DataGridView. I've set the DataSource of the DataGridView to my DataTable. My problem is that I want some of the columns to be drop downs. For example, the user will need to enter a "product" into one of the columns. There is a list of "products" in another DataTable. I would like the user to be able to click a drop down in my DataGridView to select the "product' that they want. I'm not using the the designer to set this stuff up. The DataTables are instantiated in the code. The DataGridView is now being handled in the code, but this isn't necessary. I've tried to make sense of the help screens and also some outside references, but without any success. I'd really appreciate either some guidance as to how to do this, or a reference that would help me. Thanks very much, Art Are you not using VS 2005? The new DataGrid have this feature natively. The
new DataGrid is awesome. If you are using VS 2003, you need do a very hard job to insert a well-working combobox in the DataGrid. So, look for articles on Internet to help (a bit) you do that. Personally, I think is better you consider upgrading your VS, if is the case. I told the new DataGrid is awesome, already??? Show quoteHide quote :^P Cesar "Art" <A**@discussions.microsoft.com> wrote in message news:FD7F0111-2721-46AD-B691-69848A45B570@microsoft.com... > Hi, > > Forgive me for posting this message in 2 groups -- it appears that the > Data > Access group isn't very active, so I'm posting again here: > > I have a DataTable that I want to fill using a DataGridView. I've set the > DataSource of the DataGridView to my DataTable. My problem is that I want > some of the columns to be drop downs. For example, the user will need to > enter a "product" into one of the columns. There is a list of "products" > in > another DataTable. I would like the user to be able to click a drop down > in > my DataGridView to select the "product' that they want. > > I'm not using the the designer to set this stuff up. The DataTables are > instantiated in the code. The DataGridView is now being handled in the > code, > but this isn't necessary. > > I've tried to make sense of the help screens and also some outside > references, but without any success. I'd really appreciate either some > guidance as to how to do this, or a reference that would help me. > > Thanks very much, > > Art Actually I am using VS2005. I see that I can tell a column to be a ComboBox
-- that works. Unfortunately I can't seem to figure out how to tell it where to get the data for the list. The GridView itself has a different DataTable as its source. Art Show quoteHide quote "ronchese" wrote: > Are you not using VS 2005? The new DataGrid have this feature natively. The > new DataGrid is awesome. > > If you are using VS 2003, you need do a very hard job to insert a > well-working combobox in the DataGrid. So, look for articles on Internet to > help (a bit) you do that. > Personally, I think is better you consider upgrading your VS, if is the > case. > > I told the new DataGrid is awesome, already??? > > :^P > Cesar > > > "Art" <A**@discussions.microsoft.com> wrote in message > news:FD7F0111-2721-46AD-B691-69848A45B570@microsoft.com... > > Hi, > > > > Forgive me for posting this message in 2 groups -- it appears that the > > Data > > Access group isn't very active, so I'm posting again here: > > > > I have a DataTable that I want to fill using a DataGridView. I've set the > > DataSource of the DataGridView to my DataTable. My problem is that I want > > some of the columns to be drop downs. For example, the user will need to > > enter a "product" into one of the columns. There is a list of "products" > > in > > another DataTable. I would like the user to be able to click a drop down > > in > > my DataGridView to select the "product' that they want. > > > > I'm not using the the designer to set this stuff up. The DataTables are > > instantiated in the code. The DataGridView is now being handled in the > > code, > > but this isn't necessary. > > > > I've tried to make sense of the help screens and also some outside > > references, but without any success. I'd really appreciate either some > > guidance as to how to do this, or a reference that would help me. > > > > Thanks very much, > > > > Art > > > You need to set some properties of the combobox column. Check the full sample below:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dtr As DataRow 'create main table Dim dtbMain As New DataTable dtbMain.Columns.Add("people_name", GetType(String)) dtbMain.Columns.Add("gender_id", GetType(Integer)) 'fill main table '1 dtr = dtbMain.NewRow dtr.Item("people_name") = "Cinthia" dtr.Item("gender_id") = 2 dtbMain.Rows.Add(dtr) '2 dtr = dtbMain.NewRow dtr.Item("people_name") = "Peter" dtr.Item("gender_id") = 1 dtbMain.Rows.Add(dtr) '3 dtr = dtbMain.NewRow dtr.Item("people_name") = "Mary" dtr.Item("gender_id") = 2 dtbMain.Rows.Add(dtr) 'create gender table Dim dtbGender As New DataTable dtbGender.Columns.Add("gender_id", GetType(Integer)) dtbGender.Columns.Add("gender_name", GetType(String)) 'fill genders '1 dtr = dtbGender.NewRow dtr.Item("gender_id") = 1 dtr.Item("gender_name") = "Male" dtbGender.Rows.Add(dtr) '2 dtr = dtbGender.NewRow dtr.Item("gender_id") = 2 dtr.Item("gender_name") = "Female" dtbGender.Rows.Add(dtr) With DataGridView1 .Columns.Clear() .AutoGenerateColumns = False Dim colName As DataGridViewTextBoxColumn colName = New DataGridViewTextBoxColumn colName.Name = "name" colName.HeaderText = "Name" colName.DataPropertyName = "people_name" Dim colGender As DataGridViewComboBoxColumn colGender = New DataGridViewComboBoxColumn colGender.Name = "gender" colGender.HeaderText = "Gender" colGender.DataPropertyName = "gender_id" colGender.DataSource = dtbGender colGender.DisplayMember = "gender_name" colGender.ValueMember = "gender_id" .Columns.Add(colName) .Columns.Add(colGender) .DataSource = dtbMain End With End Sub []s Cesar Show quoteHide quote "Art" <A**@discussions.microsoft.com> wrote in message news:70F0A897-225F-453E-98D1-15AE9574FD11@microsoft.com... > Actually I am using VS2005. I see that I can tell a column to be a ComboBox > -- that works. Unfortunately I can't seem to figure out how to tell it where > to get the data for the list. The GridView itself has a different DataTable > as its source. > > Art > > "ronchese" wrote: > >> Are you not using VS 2005? The new DataGrid have this feature natively. The >> new DataGrid is awesome. >> >> If you are using VS 2003, you need do a very hard job to insert a >> well-working combobox in the DataGrid. So, look for articles on Internet to >> help (a bit) you do that. >> Personally, I think is better you consider upgrading your VS, if is the >> case. >> >> I told the new DataGrid is awesome, already??? >> >> :^P >> Cesar >> >> >> "Art" <A**@discussions.microsoft.com> wrote in message >> news:FD7F0111-2721-46AD-B691-69848A45B570@microsoft.com... >> > Hi, >> > >> > Forgive me for posting this message in 2 groups -- it appears that the >> > Data >> > Access group isn't very active, so I'm posting again here: >> > >> > I have a DataTable that I want to fill using a DataGridView. I've set the >> > DataSource of the DataGridView to my DataTable. My problem is that I want >> > some of the columns to be drop downs. For example, the user will need to >> > enter a "product" into one of the columns. There is a list of "products" >> > in >> > another DataTable. I would like the user to be able to click a drop down >> > in >> > my DataGridView to select the "product' that they want. >> > >> > I'm not using the the designer to set this stuff up. The DataTables are >> > instantiated in the code. The DataGridView is now being handled in the >> > code, >> > but this isn't necessary. >> > >> > I've tried to make sense of the help screens and also some outside >> > references, but without any success. I'd really appreciate either some >> > guidance as to how to do this, or a reference that would help me. >> > >> > Thanks very much, >> > >> > Art >> >> >> |
|||||||||||||||||||||||