473,587 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_ch ang
and my code for this event was
private void dataGrid1_Curre ntCellChanged(o bject sender,System.E ventArgs ne

dataGrid1.Selec t(dataGrid1.Cur rentCell.RowNum ber)
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 1173
Hi,

The sample below will help you further.

Good Luck
Adnan

Sampel use of the MouseUp event
private void dataGrid1_Mouse Up(object sender, System.Windows. Forms.MouseEven tArgs e)
{
DataGrid myGrid = (DataGrid)sende r;
DataGrid.HitTes tInfo myHitInfo = myGrid.HitTest( e.X, e.Y);
if (myHitInfo.Type == DataGrid.HitTes tType.Cell || myHitInfo.Type == DataGrid.HitTes tType.RowHeader )
{
myGrid.Select(m yHitInfo.Row);
myGrid.CurrentR owIndex = myHitInfo.Row;
int someSampleID = Convert.ToInt16 (myGrid[myHitInfo.Row,0]);
}
}
"Gidi" <sh*****@hotmai l.com> wrote in message news:B4******** *************** ***********@mic rosoft.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_ch ange
and my code for this event was:
private void dataGrid1_Curre ntCellChanged(o bject sender,System.E ventArgs ne)
{
dataGrid1.Selec t(dataGrid1.Cur rentCell.RowNum ber);
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\d own) 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
1279
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 in my storedprocedure and sent it back to the application? 2. how can i make my dataGrid to display the last rows and not the first? 3. my last...
3
1516
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 to be at the last line, so i can see the last lines, how can i make it to be at the bottom? 2. i made a flag that disable the option to create...
2
1210
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 Comboboxes, can we display multiple fields ? For example in a Form of customers, we have a combo box to select the customer you want to change, so in that...
0
257
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 looks like <asp:datagrid id="datagrid1" runat="Server" allowpaging="true" pagesize="25" autogeneratecolumns="False"> <asp:hyperlinkcolumn...
1
1701
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? Application is across all sessions. Session is across all pages. ViewState is sort of like Session, but for only one page. <-- Correct statement? ...
9
1302
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 some problems by using session("conMain"), see question 2). I don't know if it's a good thing to do, and not oppenning at each page the
10
1417
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 you'll get the left one autosized to it's content, I want to do that when I load the grid with data. 2. How do you sort the grid using a command...
1
3203
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 datasources. Then at run time when I would bind a dataset to the grid it would display the tablestyle associated with the dataset. How do I do this in...
3
1095
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 select "getNews"(the datatable) to show my data. 2.) I have this set up to a loop. So after I view my grid any updates in the loop causes the...
0
1259
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 from a datatable and enable it to allow edits as well.
0
7852
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8216
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. ...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8221
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...
0
6629
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...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
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...
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1192
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...

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.