View Full Version : help! SplitContainer prevent DataGridView from getting keyboard's input
cannan 08-17-2009, 04:59 PM please help! Denis or anybody else who knows dotnet well
I have a dataGridView inside a SplitContainer, and I can't edit the text inside the dataGridView, it doesn't respond to pressing the keyboard (instead it activates the shortcut keys on Max)
here's an example code:
rollout ro_ROLLOUT_NAME "ROLLOUT_NAME"
(
local rolWidth = 800
local rolHeight = 600
local dgvGrid
dotNetControl scContentSplitter "System.Windows.Forms.SplitContainer" pos:[0,0] width:rolWidth height:rolHeight
fn openDialog = (
createDialog ro_ROLLOUT_NAME width:rolWidth height:rolHeight
dgvGrid = dotNetObject "System.Windows.Forms.DataGridView"
scContentSplitter.Panel1.controls.add dgvGrid
labels = #("col 1", "col 2")
dgvGrid.ColumnCount = labels.count
for i=1 to labels.count do dgvGrid.Columns.item[i-1].Name = labels[i]
dgvGrid.rows.add #((dotNetObject "System.String" "some"), (dotNetObject "System.String" "thing"))
)
)
ro_ROLLOUT_NAME.openDialog()
I guessed it some kind of focus problem but didn't manage to get around it!
|
|
martroyx
08-17-2009, 08:33 PM
you need to desactivate max internal keyboard overwrite when you beginedit your cell ...
rollout ro_ROLLOUT_NAME "ROLLOUT_NAME"
(
local rolWidth = 800
local rolHeight = 600
local dgvGrid
dotNetControl scContentSplitter "System.Windows.Forms.SplitContainer" pos:[0,0] width:rolWidth height:rolHeight
fn openDialog = (
createDialog ro_ROLLOUT_NAME width:rolWidth height:rolHeight
dgvGrid = dotNetObject "System.Windows.Forms.DataGridView"
-->
dotnet.addeventhandler dgvGrid "CellBeginEdit" (fn doit s e =enableaccelerators=false)
dgvGrid.tag=dotNetMXSValue dgvGrid
-->
scContentSplitter.Panel1.controls.add dgvGrid
labels = #("col 1", "col 2")
dgvGrid.ColumnCount = labels.count
for i=1 to labels.count do dgvGrid.Columns.item[i-1].Name = labels[i]
dgvGrid.rows.add #((dotNetObject "System.String" "some"), (dotNetObject "System.String" "thing"))
)
)
ro_ROLLOUT_NAME.openDialog()
hope this help :-)
Martin
denisT
08-17-2009, 08:43 PM
please help! Denis or anybody else who knows dotnet well
I have a dataGridView inside a SplitContainer, and I can't edit the text inside the dataGridView, it doesn't respond to pressing the keyboard (instead it activates the shortcut keys on Max)
...
I guessed it some kind of focus problem but didn't manage to get around it!
First, I told you that you have to use any other control as parent of splitContainer. In your sample the SplitContainer is not working.
Second, definitely it's something wrong with "in focus" state of gridView... I added "click" event handler to gridView... It kinda helps, but it doesn't look clean for me...
Maybe anyone else has a better solution.
In theory if you add any control as a child to any other control, you have to take care about child control event handlers yourself...
try(destroydialog ro_ROLLOUT_NAME) catch()
rolWidth = 800
rolHeight = 600
rollout ro_ROLLOUT_NAME "ROLLOUT_NAME"
(
fn vc c = (dotNetClass "System.Drawing.Color").fromARGB c.r c.g c.b
dotNetControl lb "System.Windows.Forms.Label" pos:[0,0] width:rolWidth height:120
local dgvGrid = dotNetObject "System.Windows.Forms.DataGridView"
local splitter = dotNetObject "System.Windows.Forms.SplitContainer"
fn clickGrid s e =
(
enableaccelerators = off -- thanks to Martin ... it works
--lb.focus()
--s.focus()
)
fn initGridView gv: size: =
(
-- gv.size = dotNetObject "System.Drawing.Size" (size.x) (size.y)
gv.Dock = gv.Dock.Fill
labels = #("col 1", "col 2")
gv.ColumnCount = labels.count
for i=1 to labels.count do gv.Columns.item[i-1].Name = labels[i]
gv.rows.add #((dotNetObject "System.String" "some"), (dotNetObject "System.String" "thing"))
dotNet.addEventHandler gv "click" clickGrid
gv
)
on ro_ROLLOUT_NAME open do
(
splitter.Dock = (dotnetclass "System.Windows.Forms.DockStyle").Fill
splitter.Panel1.BackColor = (dotnetclass "System.Drawing.Color").Yellow
lb.controls.add splitter
splitter.Panel1.controls.add (initGridView gv:dgvGrid size:[splitter.Panel1.width, splitter.Panel1.height])
--lb.focus()
)
)
createDialog ro_ROLLOUT_NAME width:rolWidth height:rolHeight
cannan
08-18-2009, 08:05 AM
it works! wow you guys are awesome!!
Thank you very much Martin!
Denis - you're right! I kind of compose the example in a hurry, sorry!
should I turn on the accelerators after finish edit?
denisT
08-18-2009, 04:18 PM
should I turn on the accelerators after finish edit?
As I know you haven't to set enableaccelerators back to previous state. Honestly I was surprised to see that accelerators still make sense for .NET.
CGTalk Moderation
08-18-2009, 04:18 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.