.NET 1.1 DataGrid Selection

mafrosis

Well-known member
Joined
Jun 5, 2006
Messages
88
Location
UK
Programming Experience
5-10
Hey all,

Does anyone know a way to stop a DataGridTextBoxColumn from displaying it's TextBox?

I have a ReadOnly grid, where each row selects in full, but it looks crappy when the TextBox shows up in each cell.

Here's the code to force the selection of the whole row:

VB.NET:
[COLOR="Blue"]Private Sub[/COLOR] dgTeamA_CurrentCellChanged([COLOR="Blue"]ByVal [/COLOR]sender [COLOR="Blue"]As [/COLOR]System.Object, [COLOR="Blue"]ByVal [/COLOR]e [COLOR="Blue"]As [/COLOR]System.EventArgs) _
	[COLOR="Blue"]Handles [/COLOR]dgTeamA.CurrentCellChanged
	
	dgTeamA.Select(dgTeamA.CurrentRowIndex)
[COLOR="Blue"]End Sub[/COLOR]

And here's the example of the rendered display when you click a cell:

grid.png


Thanks all
mafro
 
Yeh sorry about that - I live in .NET 2.0 world, it's just this app ive been developing as a favour for someone is 1.1 (hence the post's subject!)

DataGridTextBoxColumn certainly is in 1.1 - im using it..

As for the final point, there is no such thing as a "standard" column - the default is a DataGridTextBoxColumn.. And hence the greyed textbox which appears for readonly..

MSDN DataGridColumnStyle Ref (VS.71)

The System.Windows.Forms.DataGrid control automatically creates a collection of DataGridColumnStyle objects for you when you set the DataSource property to an appropriate data source. The objects created actually are instances of one of the following classes that inherit from DataGridColumnStyle: DataGridBoolColumn or DataGridTextBoxColumn class.

Your input is appreciated Arg - my last couple of posts went nowhere..
Cheers
mafro
 
None of my 1.1 apps showed a textbox like that, and I was using 10+ read only grids which the user could select a row....

When I say standard I mean after dropping a grid onto the form, before you do any formatting with the datagridcolumnstyle.

I never went that far with my grids, as on another app which needed it I ended up buying ComponentOne, which I'm still using in .net 2.0

Sorry I couldn't be of much help, looking on the net doesn't seem to return much either...
 
Ok man, thanks for your help.

Ive been having all kinds of trouble with this - i created my own custom ColumnStyle which overrode the Edit method to do nothing, which didnt work. I then overrode the Edit method to just put a Label control in the DataGrid cell and then just Commit the original data back to the source - this also didnt work.

You can the see the errors I receive using either of the 2 methods above in this post:
http://www.vbdotnetforums.com/showthread.php?t=19847

I think I might have to get myself ComponentOne to get this project out of the door - then never use 1.1 again! Never have any of these probs with DataGridView.. Ah well.

As a quick example, this code will demonstrate what im seeing (code works in a VS8 project too). Just paste it into a new forms project.

VB.NET:
[COLOR="Blue"]Private [/COLOR]dt [COLOR="Blue"]As [/COLOR]DataTable	
[COLOR="Blue"]Private [/COLOR]dg [COLOR="Blue"]As [/COLOR]DataGrid

[COLOR="Blue"]Private Sub[/COLOR] Form1_Load([COLOR="Blue"]ByVal [/COLOR]sender [COLOR="Blue"]As [/COLOR]System.Object, [COLOR="Blue"]ByVal [/COLOR]e [COLOR="Blue"]As [/COLOR]System.EventArgs) [COLOR="Blue"]Handles MyBase[/COLOR].Load
	[COLOR="Green"]'create & configure datagrid[/COLOR]
	dg = [COLOR="Blue"]New [/COLOR]DataGrid()
	dg.ReadOnly = [COLOR="Blue"]True[/COLOR]
	dg.Dock = DockStyle.Fill
	[COLOR="Blue"]Me[/COLOR].Controls.Add(dg)

	[COLOR="Green"]'create faux data source[/COLOR]
	dt = [COLOR="Blue"]New [/COLOR]DataTable()
	dt.Columns.Add([COLOR="Blue"]New [/COLOR]DataColumn("name", [COLOR="Blue"]GetType[/COLOR]([COLOR="Blue"]String[/COLOR])))
	dt.Columns.Add([COLOR="Blue"]New [/COLOR]DataColumn("age", [COLOR="Blue"]GetType[/COLOR]([COLOR="Blue"]String[/COLOR])))
	dt.Rows.Add(dt.NewRow())
	dt.Rows.Add(dt.NewRow())
	
	dt.Rows(0)("name") = "bob"
	dt.Rows(0)("age") = "22"
	
	dt.Rows(1)("name") = "fred"
	dt.Rows(1)("age") = "44"
	
	[COLOR="Green"]'databind[/COLOR]
	dg.DataSource = dt
[COLOR="Blue"]End Sub[/COLOR]
 
I think this was the reason I brought C1 !! I wanted some grids to have comboboxes in and to program this normally went straight over my head so my company coughed up for C1...much much easier for me to get done what I needed to!

..again, that doesn't really help you :D
 
Back
Top