473,804 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView - how to find out a selected cells

8 New Member
Hi, Can anybody tell me how Can I find out a indexes of cells which are selected? E.g: when I want to delete a content a cells.
thanx
Dec 21 '07 #1
9 3384
Plater
7,872 Recognized Expert Expert
For a DataGridView, an event is fired on cell selection, the event gives you the information you need.
Dec 21 '07 #2
Frinavale
9,735 Recognized Expert Moderator Expert
For a DataGridView, an event is fired on cell selection, the event gives you the information you need.
The event pass you a variable "e". This variable will contains the properties that you are looking for.
Dec 21 '07 #3
Lopy
8 New Member
Thanx a lot:]............... .....
Dec 21 '07 #4
Plater
7,872 Recognized Expert Expert
Not to mention there is a "SelectedCe lls" object that gives you all the information you need.

Which leads me to believe you put in zero effort before asking the question.
Dec 21 '07 #5
Lopy
8 New Member
I looking for a proper event but I dind't find one. May by MultiSelectChan ged but here I don't have any proper method which tell me a selected cells. Do you tell me this method psl...
Dec 21 '07 #6
Plater
7,872 Recognized Expert Expert
Events:
SelectionChange d gets fired when the selection changes(Will need to use SelectedCells to get information)
CellMouseClick gets fired when a cell is clicked.
CellMouseDouble Click gets fired when a cell is double-clicked
CellContentClic k gets fired when the contents of a cell are clicked(i.e. a button in a cell)

Almost any event can give you the information you request....

Properties:
.SelectedCells gives the collection of cells currently selected.
.SelectedRows gives the collection of rows currently selected
Dec 21 '07 #7
Lopy
8 New Member
An event SelectedCells don't give a selected cells. SelectedCells.C ount give me a count of selected cells. Any proper method or properties don't return an int value. If I make anywhere mistake, do you tell me a correct solution pls.
Dec 21 '07 #8
Plater
7,872 Recognized Expert Expert
SelectedCells is a COLLECTION.
SelectedCells[0] is the first selected cell (if exists)
SelectedCells[1] is the second selected cell (if exists)
etc


If you are having trouble with these things, I recomend reading up on some tutorials
Dec 21 '07 #9
Lopy
8 New Member
oh. OK. great..........
Dec 21 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
22394
by: Henry J. | last post by:
Can somebody tell me how to delete multiple rows in a datagridview selected by the user? I tried the following two methods to no avail. I have a myDataGridView that is bound to myDataTable's myDataView. The column "Name" is the primary key. I want to delete the rows selected by the user: foreach (DataGridViewRow drv in myDataGridView.SelectedRows) {
1
4167
by: Riley | last post by:
Need some help. I am using datagridview in 2005 with C#. I am calling a web service and filling the datagridview with the data returned. This all works fine. Next step is to take a value from one of the cells in the datagridview and return it back with some other values in an object for another webservice call. The problem is I dont know how to access a cell in a datagridview to do this. Im pretty sure you have to do it thru the binding...
3
4662
by: Daniel Manes | last post by:
I need a strategy to debug this situation... I can't put all the code involved, but here are some of the critical lines with comments: ------------------------- Private _parentDataCell As DataGridViewCell 'declare private field _parentDataCell = _parentDataGrid.Rows(rowIndex).Cells(columnIndex) 'set to a specific cell Debug.Print(_parentDataCell.DataGridView.ToString) 'prints:
4
21312
by: Hexman | last post by:
Hello All, I'd like to find out the best way to add a cb column to a dgv and process efficiently. I see at least two ways of doing it. ------------------------------- 1) Add a cb to the dgv, iterate thru the dgv and update the bound fields if the cb has been checked. Then do the update and accept changes. How do I access the cb and its checked status? How to iterate thru dgv? Dim cbSelCol As New DataGridViewCheckBoxColumn
4
34078
by: Annie | last post by:
hello guys, I am having a DataGridView control. The first column is a checkbox column. The users can select the checkbox column. I need to loop through the grid rows and get the checked checkboxes and the rows numbers
3
35766
by: SimonHeffer | last post by:
I've added a DataGridView and added some columns in the designer, now I want to add some rows with data applied via column name. Having done some web trawling I've ended up with this: private void AddRow(string thing,string thingdesc) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(MyGrid); // #1 row.Cells.Value = "Add"; // #2 this makes it work MyGrid.Rows.Add(row); ...
20
20341
by: Phil | last post by:
VB2008 I have a DataGridView with MultiSelect = True and SelectionMode=FullRowSelect. One of the columns is a checkbox column. I have a function that goes through all the selected rows and sets the value of this column. For Each row In DataGridView1.SelectedRows row.Cells("MyCheckboxColumn").Value = False Next
0
1026
by: richkid | last post by:
hello, I have a datagridview on my form that is populated with thousands of records from a database. When I add a new product, I want the new product to be the one selected. I've tried aot of different things and cant seem to achieve this. The following HIGHLIGHTS the new row but not SELECT it.The first row is still selected (the little arrow cursor in the row header) is set on the first record. The DGV imulti select property is set to...
3
11934
by: sheridan | last post by:
Hi everyone. I'm hoping somone can help me, because I've been stuck on this all evening and haven't found the answer online yet. I have a DataGridView control and have managed to change all of the BackColors and GridColors of all of the cells, alternating row cells and selected cels. I have also sucessfully changed the BackColors of the RowHeaders and ColumnHeaders, but I can't for the life of me find out how to change the colour of the...
2
11601
by: cday119 | last post by:
Hi Everyone, So I have a datagridview and it has a column called status. It has 3 values: New, Printed, and Shipped. Now a user can select multiple rows and click "set to printed". I then do a foreach loop on datagridview.selectedrows and change the status to printed. Now the problem is that if the datagridview is sorted by status, when the status is changed from new to printed, that row is moved from being under new to printed and all...
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.