System.Windows.Forms.DataGrid

  • Thread starter Thread starter scott
  • Start date Start date
S

scott

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
 
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
TextBoxColumnStyle (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,

Build you table style using the following datagridtextboxcolumn. It will
select the entire row and not enter the individual columns.


private class DataGridNoActiveCellColumn : DataGridTextBoxColumn
{
protected override void Edit(System.Windows.Forms.CurrencyManager
source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly,
string
instantText, bool cellIsVisible)
{
this.DataGridTableStyle.DataGrid.Select(rowNum);
}
}
 
If you're trying to select a row with the right mousebutton you could use
code like this I guess:

private void dataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
System.Drawing.Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);
if(hti.Type == DataGrid.HitTestType.Cell)
{
dataGrid1.CurrentCell = new DataGridCell(hti.Row, hti.Column);
dataGrid1.Select(hti.Row);
}
}

You can find this code on:
http://www.syncfusion.com/FAQ/WinForms/FAQ_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...
 
Back
Top