473,659 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Windows. Forms.DataGrid

hi all, hope some one can help

iv created a datagrid that points to a DataView. the data view takes in a
DataTable. The DataTable then adds the columns using DataColumn.

All fine so far.

The table is set up and i can add stuff to it (text).

however i had made it so that u can't change the text wtih in the table,
which is what i want, but it still lets u select the text.

I want to make it so i just click on a row and all it does is select that
row. iv made is so that when u click on a row it does select that row, but
if u click again it slects the text with in that cells.

Idealy what i want to do is right click on any row, when i do that it
selects that row and pops up a menu that will allow we to remove that row
from the table. Im not worried about the pop up menu at the moment though
as i can't even get it to select a row when i right click and i need to stop
it selecting the text.

Can any one help me plz ? iv seen this possible in other programs but i
assume they use another programing language.

thx scott
Nov 16 '05 #1
3 2396
Hi Scott,

If i undertood you right, you want to make the cells in a datagrid not
editable. The best way to do this is to create a custom
TextBoxColumnSt yle (i'm not sure, search msdn) for every column. When
deriving the new class, you need to override only the OnEdit method
with an empty one. This method is called when the cell receives an edit
request.

To select the row on click and right click implement an event handler
for the OnMouseDown event of the datagrid. The handler should call the
Select(rowNr) method of the datagrid.
For a contextual menu, create a contextmenu on the form, then assign
its name to the contextmenu property of the datagrid.

Hope this helps,
Diablo
scott wrote:
hi all, hope some one can help

iv created a datagrid that points to a DataView. the data view takes in a DataTable. The DataTable then adds the columns using DataColumn.

All fine so far.

The table is set up and i can add stuff to it (text).

however i had made it so that u can't change the text wtih in the table, which is what i want, but it still lets u select the text.

I want to make it so i just click on a row and all it does is select that row. iv made is so that when u click on a row it does select that row, but if u click again it slects the text with in that cells.

Idealy what i want to do is right click on any row, when i do that it
selects that row and pops up a menu that will allow we to remove that row from the table. Im not worried about the pop up menu at the moment though as i can't even get it to select a row when i right click and i need to stop it selecting the text.

Can any one help me plz ? iv seen this possible in other programs but i assume they use another programing language.

thx scott


Nov 16 '05 #2
Scott,

Build you table style using the following datagridtextbox column. It will
select the entire row and not enter the individual columns.
private class DataGridNoActiv eCellColumn : DataGridTextBox Column
{
protected override void Edit(System.Win dows.Forms.Curr encyManager
source, int rowNum, System.Drawing. Rectangle bounds, bool readOnly,
string
instantText, bool cellIsVisible)
{
this.DataGridTa bleStyle.DataGr id.Select(rowNu m);
}
}


"scott" <sc***********@ hotmail.com> wrote in message
news:ct******** **@newsg4.svr.p ol.co.uk...
hi all, hope some one can help

iv created a datagrid that points to a DataView. the data view takes in a
DataTable. The DataTable then adds the columns using DataColumn.

All fine so far.

The table is set up and i can add stuff to it (text).

however i had made it so that u can't change the text wtih in the table,
which is what i want, but it still lets u select the text.

I want to make it so i just click on a row and all it does is select that
row. iv made is so that when u click on a row it does select that row, but
if u click again it slects the text with in that cells.

Idealy what i want to do is right click on any row, when i do that it
selects that row and pops up a menu that will allow we to remove that row
from the table. Im not worried about the pop up menu at the moment though
as i can't even get it to select a row when i right click and i need to
stop
it selecting the text.

Can any one help me plz ? iv seen this possible in other programs but i
assume they use another programing language.

thx scott

Nov 16 '05 #3
If you're trying to select a row with the right mousebutton you could use
code like this I guess:

private void dataGrid1_Mouse Up(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
System.Drawing. Point pt = new Point(e.X, e.Y);
DataGrid.HitTes tInfo hti = dataGrid1.HitTe st(pt);
if(hti.Type == DataGrid.HitTes tType.Cell)
{
dataGrid1.Curre ntCell = new DataGridCell(ht i.Row, hti.Column);
dataGrid1.Selec t(hti.Row);
}
}

You can find this code on:
http://www.syncfusion.com/FAQ/WinFor...c44c.asp#q689q
It works fine for the left mousebutton, but you'll still have to do some
work with the right button because it seems that the text in the previously
selected row also stays selected.
But hopefully it will help you in the right direction...
"scott" <sc***********@ hotmail.com> schreef in bericht
news:ct******** **@newsg4.svr.p ol.co.uk...
Idealy what i want to do is right click on any row, when i do that it
selects that row and pops up a menu that will allow we to remove that row
from the table. Im not worried about the pop up menu at the moment though
as i can't even get it to select a row when i right click and i need to
stop
it selecting the text.

Nov 16 '05 #4

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

Similar topics

3
9130
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in system.windows.forms.dll
0
1989
by: Victor Crudu | last post by:
Hi, could somebody help me to solve the follwing problem ? I get the following exception when i set as the DataSource of a DataGrid a DataTable. This situation can be only if I change programaticaly the minimum property of the scroll bar to be >0. But i even do not have access to the scroll bars of the grid because the scrollbars are protected. Unhandled Exception:
0
1857
by: sarah | last post by:
Using .NET C# installed Framework 1.1 with Service Pack 1 I have a MDI application in C# that contains 3 different forms. Form 1 has several controls one of which is a DataGrid control that works fine. Form 2 has several controls, none of which ia a DatGrid control. Form 3 has several controls, none of which as a DataGrid. In this configuration everything compiles and runs fine. When I add a DataGrid control to Form 3 I get the...
3
2143
by: max | last post by:
I can generate this error by NOT assigning a tableName to the view: at System.Windows.Forms.DataGrid.AddNewRow() at System.Windows.Forms.DataGridAddNewRow.OnEdit() Is there any possibility of getting an event from the AddNewRow()? I would like to make some changes to the row prior to the user typing in the DataGrid. Thanks,
5
2072
by: Sanddevil | last post by:
Hi there - I hope someone out there can help me! I'm using a .Net DataGrid Class to show the results of a SQL query in a spreadsheet type control. The code, which works fine is: iRowCount = oleDbDataAdapter1->Fill(dataSet1); dataGrid1->DataSource = dataSet1->Tables->Item->DefaultView;
3
2384
by: mahtan | last post by:
Please help I have the problem that when I change the data in a Windows.Forms.DataGrid by a separate thread the following Exception is thrown: ThreadSystem.NullReferenceException in system.windows.forms.dll I can't catch this Exception and it only occurs when I
1
2113
by: melanieab | last post by:
Hi, I'm have a datagrid, and I'm trying to have a tooltip pop up if a cell has been hovered on for 2 seconds. I was thinking of using DataGrid.Hover, but then decided to try this instead: static System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); private void dg_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { System.Timers.Timer timer = new System.Timers.Timer();
3
1093
by: melanieab | last post by:
Hi, I'd been saying DataGrid.HitTestInfo HitInfo = dg.HitTest(e.X, e.Y); for a while without any problem (of course with using System.Windows.Forms;). Then suddently I got errors and had to add System.Windows.Forms. in front of DataGrid.HitTestInfo. Just wondering if anyone knew of possible reasons for this. Thanks! Melanie
1
2791
by: Rajesh Kumar Choudhary | last post by:
Hi, I want to use the system.windows.form.datagrid control present in .net 2005 or 2003. Is it possible to use this? Please let me know if it is not supported. I have seen and used the classes from FCL using system.tlb or mscorelib.tlb from dot net framework. I could use ArrayList successfully without any issue.
0
1971
by: Mike | last post by:
Hi, I have a collection object bound to a data grid, after I remove an item from the collection, the minute I click on the datagrid I get an error saying the specified argument was out of the range of valid values. After I remove the element from the collection I clear the databindings from the data grid and rebind it but as far as I can tell the collection seems to be the right size but for some reason when I
0
8339
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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
8751
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8535
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7360
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...
0
5650
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
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...
1
2757
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
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.