473,395 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Few questions about DataGrid...

hello
i have a DataGrid Table and i want to select a row by Clicking the mouse
after i tried few times, i understood the the only event the the datagird respones to is the current_cell_chang
and my code for this event was
private void dataGrid1_CurrentCellChanged(object sender,System.EventArgs ne

dataGrid1.Select(dataGrid1.CurrentCell.RowNumber)
this.dataGrid1.Focus()

the problem is that it's selects the whole row except the current_cell (it sets the focus on that cell) and the problem is that i can't make the dataGrid to respone to other events..

what should be the problem? or what is the solution

thanks
Nov 16 '05 #1
4 1165
Hi,

The sample below will help you further.

Good Luck
Adnan

Sampel use of the MouseUp event
private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
DataGrid myGrid = (DataGrid)sender;
DataGrid.HitTestInfo myHitInfo = myGrid.HitTest(e.X, e.Y);
if (myHitInfo.Type == DataGrid.HitTestType.Cell || myHitInfo.Type == DataGrid.HitTestType.RowHeader )
{
myGrid.Select(myHitInfo.Row);
myGrid.CurrentRowIndex = myHitInfo.Row;
int someSampleID = Convert.ToInt16(myGrid[myHitInfo.Row,0]);
}
}
"Gidi" <sh*****@hotmail.com> wrote in message news:B4**********************************@microsof t.com...
hello,
i have a DataGrid Table and i want to select a row by Clicking the mouse.
after i tried few times, i understood the the only event the the datagird respones to is the current_cell_change
and my code for this event was:
private void dataGrid1_CurrentCellChanged(object sender,System.EventArgs ne)
{
dataGrid1.Select(dataGrid1.CurrentCell.RowNumber);
this.dataGrid1.Focus();
}
the problem is that it's selects the whole row except the current_cell (it sets the focus on that cell) and the problem is that i can't make the dataGrid to respone to other events...

what should be the problem? or what is the solution?

thanks
Nov 16 '05 #2
Hi Gidi,

I'm a little confused. The current cell is selected with the rest of the row, and clicking on a cell causes it to change to edit mode. If you don't want the user to edit the values, why not simply use a ListView instead, with FullRowSelect = true

You might want to take a look at DataView, which has more functionality than a DataGrid.

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
Morten,
thank you it worked...
now i have another question...
if i'm pressing the scroll arrows (move the datagrid left\right\up\down) the cell which i pressed gets the focus (as before)
how can i make the row stay selected even if i pressed the scroll arrow
Nov 16 '05 #4
That is a very good question, that I don't know the answer for. You need to trap the key events first, but even though a datagrid has key events they never seem to fire. Setting the parent form's KeyPreview won't give it key events from the datagrid either. Nor does inheriting DataGrid and overriding the OnKeyDown event. Bug?

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gidi | last post by:
hello, i have a datagrid (in C#) and i have 3 questions: 1. how can i know how many rows my dataGrid(dataSet\DataAdapter) has? is it possiable to know with asking the database or i must do it...
3
by: Gidi | last post by:
hello i'm writing an appliction in C# and i have 2 questions: 1. i have a dataGrid which contains data from my DataBase, and when the dataGrid loads the scroll is at the first line and i want it...
2
by: Hemang Shah | last post by:
Hello I've few questions regarding ADO & C#: 1) Is it possible to view tata from multiple tables in the Datagrid control ? Most of the examples I see are only for 1 table. 2) In...
0
by: smith.felicity | last post by:
I have two questions about using the data grid and c# If one of my columns returned in my dataset is null I want another column to be used in the displayed column. So this is what my datagrid...
1
by: Sky | last post by:
Although I've been using C# for the last month or so, and accepting out of blind faith the ViewState, I do have some nagging questions about it... can you help verify the following statements? ...
9
by: eitan | last post by:
Hello, I am using Microsoft Visual Studio 2003 .NET. I have several question, please. 1) I have a connection to the database, which I create it at login, by application("conMain") (I have...
10
by: Kejpa | last post by:
Hi, I've just started using the datagrid and I have a few questions on it... 1. How do you autosize the columns to fit the content programmatically? When you double click between two columns...
1
by: Brian | last post by:
I've got a couple questions on the new Datagridview control in VS2005. 1) In the old datagrid control at design time I was able to add multiple tablestyles with columns from different...
3
by: melton9 | last post by:
I'm just getting into using datagrid and have a couple of questions. 1.)How do you get the grid to show the values of a datatable automatically? Currently I have to hit the + sign and then...
0
by: Newish | last post by:
Hi Couple of questions on datagrid 1) Is there a performance issue when using datagrid to display data from a datatable. 2) Is there a security issue when using datagrid to display data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.