DataGridView Get Index Of Selected Column?
May 15, 2010
I have a DataGridView containing a large number of columns. I want the users to be able to select multiple columns and then select a menu item to hide the selected columns. For example a user might selected columns 5 through 10 and I want the program to hide those columns. I know how to hide columns, one at a time. I can get the count of selected columns but I have not figured out how to get the index to the left-most selected column. Trial and error is such a slow process.
Considering the huge number of options offered by the DataGridView tool, it would be nice if this forum had a special category for the DataGridView (common to VB and C#).
Finally I got the desired results but it took a lot of coding, looping through the selected cells to find the one with the lowest column index, then a second loop to count previously-hidden columns, then a third loop for hiding the selected columns, stepping past previously-hidden columns and declining to hide frozen columns.
View 7 Replies
ADVERTISEMENT
Jan 18, 2012
Is there a way to find the column index of a datagridview column using the columns DataPropertyName?I currently use a loop (shown below in the class) which is kind of ugly, but it works. I'd like to do something like this, which seems more elegant.My goal is this, I store the users DataGridView column settings (i.e. DisplayIndex, Visible, & Width).When the user opens the form that contains the datagridview I want to get those settings from the database and apply the settings to the datagridview.[code]
View 5 Replies
Oct 13, 2008
I can't seem to set the selected index or selected value of a DataGridView combobox when loading data from a database. My DGV has two combobox columns which are bound to datatables. The DGV itself is not bound initially. After adding a row, I select a value from each combobox which then populates the rest of the cells in the row. I'm using the EditingControlShowing event to add an eventhandler to catch the SelectedIndexChange of the combo boxes. This all works as needed. My issue comes when populating the DGV with saved data, I need to add the rows and set the selected index and/or selected value of each combo box. I've searched through various forums and articles for the last week with no luck.
I'm using VS2008 sp1, .NET 3.5 sp1 and SQL 2005 sp2 Express.
View 8 Replies
Jun 7, 2011
How to find the seleted row index of datagridview
View 1 Replies
Mar 24, 2012
how do i get the selectedindex/item of a datagridview combobox column?what i want to do is change the back color of datagridcombobox when something is selected from the combobox?So, selecting 'false' will change the color to RED and selecting 'true' changes the color to GREEN.
View 39 Replies
Jun 6, 2009
I have datagridview with XSD as the binding source (i configured it with the smart tags). After build, the dgv change its columnIndex which surely result error of my code.
For example
columnIndex(0) = idEmployee (dataGridViewTextBoxColumn)
columnIndex(1) = name (dataGridViewTextBoxColumn)
columnIndex(2) = status (dataGridViewCheckBoxColumn)
suddenly, the columnIndex(2) moved into columnIndex(0)
View 5 Replies
Apr 20, 2009
I am trying to sort a column in DGV as follows:
DataGridView8.Sort(DataGridView8.Columns(0), ListSortDirection.Ascending)
However, I want to use the name of the column and extract the index number in the first parameter of the Sort method. However this fails:
DataGridView8.Sort(DataGridView8.Columns("Date").Index, ListSortDirection.Ascending)
View 2 Replies
May 16, 2012
i have two datragridviewcomboboxcolumn,and two textbox column in a datagridview.each combobox column is binded to separate binding source.
column names are sl_no,col_empname,col_empworktype,Col_Hours etc.and
displaymember,datapropertyname,valuemember and for comboxcolumn are
col_empname:-emp_name,emp_id,emp_id
col_empworktype:-worktypename,worktypeid,worktypeid
[Code]...
View 1 Replies
Dec 17, 2010
I have a datagridview with 3 columns. The second column is a combobox which I want to bind with a dataset. How do I go about setting the column index for it as I am doing something like this.
Dim ComboCol As New DataGridViewComboBoxColumn
ComboCol.DataSource = SDS.Tables(0)
ComboCol.ValueMember = "Specie"[code].....
View 3 Replies
Dec 19, 2009
Problem: Calling a method which uses a cell's value from a DataBound DataGridView. Works as desired without adding an image column.When I add the image column, the method attempts to use the value from column 1 instead of column 2, as the code in the 2nd method below ("findSign") states:
vb
Private Sub getAtmTOF()
Try
[code].....
View 11 Replies
Jan 25, 2010
how do you find out which COLUMN has the control or is sected in a datagridview in vb .net.
View 4 Replies
Mar 29, 2012
i would like to know how i get the selected value of a datagridview combobox column?
View 1 Replies
May 16, 2012
I'm hiding the "EmployeeID", my Primary key that is part of my datagridviews datasource. I need to get the value of that hidden column of the selected row of my datagridview. How do I go about doing that?
View 1 Replies
Feb 23, 2011
I am having datagridview in that I have datagridview combobox column and noraml textfield. I want to know that how can I load selected value in that combox box when I am loading all entered details in data grid view.
View 1 Replies
Mar 6, 2010
I'm trying to validate that a particular column in a datagridview has been selected.
I've created this code which transfers the value of the selected Customer ID cell in the datagridview to another form.
Private Sub mnuFileEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileEdit.Click
'Define variable for the current selected cell value
[Code]....
It's working fine but at the moment any column in the datagridview can be selected and transferred which causes an error.
So I want to create an If Then statement which confirms that the selected column with the dgv is the PK_ID (customer ID) column before processing the rest of the code. I've tried playing around with "If dgvCustomerSearch.SelectedColumns("PK_ID") Then" but a "Value of type...cannot be converted to Integer" error occurs.
View 2 Replies
Jun 25, 2011
i have 2 datagridcomboboxcolumn (datagridcomboboxcolumn1 and datagridcomboboxcolumn2).
With datagridcomboboxcolumn1
.DataSource = ds.Tables(0)
.ValueMember = "column1"
.DisplayMember = "column2"
[Code]....
how i can set selected item in datagridcomboboxcolumn2 become to "a" when selected item in datagridcomboboxcolumn1 is "1"or otherwise set selected item in datagridcomboboxcolumn1 become to "1" when selected item in datagridcomboboxcolumn2 is "a"??
View 6 Replies
Aug 31, 2010
is my main form.and frmpayable is frmmain's child from.in the frmpayable my code is
Dim frmreleasing As frmPostap
frmreleasing = New frmPostap(Me, release_record)
frmreleasing.MdiParent = Me.MdiParent
[code].....
View 8 Replies
Nov 15, 2011
In my datagridview there are two dependent columns, one is category and the other is items. So I want to filter my item column list as per selected category. But the problem is that when I change the category wise data to datasource of items combobox, previous selected items names disappear because previous items is not in current datasource.
View 1 Replies
Apr 23, 2012
i am having trouble putting a value in a textbox. Each time a ticket is sold i put the total price in a textbox, each time a ticket is sold for the same concert it increases by adding its self to the total price. It works at the first sale, but after that it breaks down. here is the code
Private Function DisplayMoneyTaken() As Integer
Dim totalMoney As Integer
'open the database connection
[Code].....
View 1 Replies
Jun 5, 2011
This is something that's been bugging me for a while. Say I have a dgv with several columns and rows of data. Many times while working with the grid, it's necessary to know the number of the column, but all you know is the column header name, or vice versa. Is there any internal command that will return these values, or is there at least a better solution to the problem than making a function that loops through every header name until you find the one you want? It just seems so inefficient.
View 2 Replies
Dec 9, 2009
I am using Sub to format datagridview but during Form_Load this error occur. There are rows in datasource and dg.row.count is > 0.
.Columns(0).Width = 50 <==== ERROR HERE
.Columns(1).Width = 150
.Columns(2).Width = 80
.Columns(0).HeaderText = "ID"
[code].....
View 1 Replies
Apr 6, 2010
How can i get the Column Index and the Row Index when I click on the ListView?The ListView1.FocusedItem.GetSubItemAt(e.X, e.Y).Text function only gets the text of the first column, I can't find the option of getting the Index of the Column and Row upon clicking.
View 9 Replies
Apr 14, 2009
I am working in VB 2008 and I have set up a datagridview to display rows of data which can then be selected. When I select the first row I get the error: Index was out of range. Must be non-negative and less than the size of the collection. When I select any other row the program executes as it should. From what I have learned so far is that the DataGridView has an index of -1 and that it counts the header row as part of the index which is the -1.When I select the first row through either DataGridView1_RowHeaderMouseClick or DataGridView1_CellContentClick the index is 0 for the first record. If the index is 0 I think it would fire off, but I have no idea what is happening behind the scenes. I can check the index, so when it is 0 and the code attempts to access the row, that is when I get the message.On an index number of 1 and up the code executes fine.So, is there a way to re-index the DataGridView, or is there a work around/fix for this issue?
View 2 Replies
Jan 31, 2012
I want to know How to get The last selected Index in the multi select of ListView.For example, when i select Item from index 1 to 10, so I get index 10 as the last selected index.But if i select Item from 10 to 1, so I get index 1 as the last selected index.
View 5 Replies
May 3, 2011
how to get the selected index from a listview i know you can do the "ListView.SelectedIndices.Item(0)" but then you still need to know the index of the selected item.
View 14 Replies
Dec 9, 2010
'Get the selected index of the list box 'use that selectedindex for the row of the array and get both the quantity and price into local variables in VB
[Code]...
View 6 Replies
Oct 19, 2011
Can any one tell me how can i get the current selected indel in the ListView.
I need to execute a code every time the selection changes in ListView.
I have listView with only one column. All the list will be in column 0.
I used the below code in Listview1_Click event and able to get the selected index value,but when i used the same code in the Listview1_SelectedIndexChanged and Listview1_ItemSelectionChanged its giving below below error Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click
[Code]...
View 2 Replies
Dec 6, 2011
I think I'm having a brain fart on this but I can't seem to figure out why this is not working.
Public Class Radio_Main
Dim RadioDial As String = 1
Dim Go As String = "http://"
Private Sub pb_Tuner_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pb_Tuner.Click
'My.Computer.Audio.Stop()
[Code]...
View 2 Replies
Jul 22, 2009
I drag Tabcontrol.& add two tab pages. I have contextmenu Strip, dat i bound to tabcontrol.I select the ContextMenuStrip & set it to ContextMenuStrip1
Now i right click on tab headers.Suppose i right click on tabpage1,contextmenu is displayed.I want that when i right click on tabpage..I want to get the index of that tab..Even if dat tab page is selected.[code...]
View 2 Replies
Jul 24, 2009
I drag Tabcontrol.& add two tab pages.I have contextmenu Strip, dat i bound to tabcontrol.I select the ContextMenuStrip & set it to ContextMenuStrip1Now i right click on tab headers.Suppose i right click on tabpage1,contextmenu is displayed.I want that when i right click on tabpage..I want to get the index of that tab..Even if dat tab page is selected.Ex-Mozilla.
Private Sub TabControl1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseClick
Try
[code]....
Above event gives me the index,when i select the tab.
View 2 Replies