|
-
Jun 13th, 2011, 03:16 AM
#1
Thread Starter
Frenzied Member
DataGrid
Is it possible to change the background color of a cell when I click on it?
Also, is it possible to set a property so that when a cell is clicked on once it already has the focus that the 'edit' text feature doesn't let the user to change the text?
Thanks
-
Jun 13th, 2011, 03:42 AM
#2
Lively Member
Re: DataGrid
 Originally Posted by Simon Canning
Is it possible to change the background color of a cell when I click on it?
Also, is it possible to set a property so that when a cell is clicked on once it already has the focus that the 'edit' text feature doesn't let the user to change the text?
Thanks
For changing cell properties:
Click on the datagrid control;
In the properties, you will find:
RowDefaultCellStyle: DataGridViewCellStyle { } - when you click on it a button will appear with '...' dots on it. - click on the button, and there you'll find all properties you need.
For the second question (editing):
Click on the data grid control in the VB (Not while debugging)
a Play icon will be visible on the top right of the control ->
Click the icon and select Edit Culomns -> Select the column you want to disable editing on -> Read Only -> True.
-
Jun 13th, 2011, 04:12 AM
#3
Thread Starter
Frenzied Member
Re: DataGrid
For the background color of a cell, can i change each cell individually at run time?
I have tried this:
Code:
dataGridShifts.CurrentCell.DataGridView.DefaultCellStyle.BackColor = Color.Red
But it isn't working as I want.
Also, how can i return the value of the current selected row when I click on a cell?
Last edited by Simon Canning; Jun 13th, 2011 at 04:23 AM.
-
Jun 13th, 2011, 07:22 AM
#4
Lively Member
Re: DataGrid
Have you tried this?
DataGridView1.CurrentCell.Style.BackColor = Color
-
DataGridView.Item(Column Index, Row Index) - has many properties to it, that will help you find either the value of the selected cell etc...
-
Jun 23rd, 2011, 08:23 AM
#5
Thread Starter
Frenzied Member
Re: DataGrid
OK, when i click on a cell, how can i retrieve the value of the selected cell and the row?
thanks
-
Jun 25th, 2011, 03:07 AM
#6
Lively Member
Re: DataGrid
To get all the data you need from a row:
Steps:
1. Get row index.
by the CurrentRow.Index option.
So setting row index into variable:
dim ri = Datagridview.CurrentRow.Index
Then use the DataGridView1.Item(0,ri).Value
-
Jun 25th, 2011, 09:04 AM
#7
Re: DataGrid
 Originally Posted by Simon Canning
OK, when i click on a cell, how can i retrieve the value of the selected cell and the row?
thanks
For all cells
Code:
Dim rowString = (From cell As DataGridViewCell In _
DataGridView4.Rows(DataGridView1.CurrentRow.Index) _
.Cells.Cast(Of DataGridViewCell)() _
Select cell.Value).ToArray
MsgBox(String.Join(","c, Array.ConvertAll(rowString, Function(o) o.ToString)))
For just the current selected cell
Code:
Console.WriteLine(DataGridView1.CurrentCell.Value)
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
|