Store a pointer in a DataGridView cell? (or other method of referencing a pointer) [modified]
-
Hello, I'm writing a ALT+TAB-ish app that pops up due to a hotkey. It currently displays a list of currently running applications (using EnumWindows & GetWindowText) as a row in a DataGridView and I've created a event handler to run when a row is double clicked on. I'm hoping to use SetForeGroundWindow from User32.dll to bring the selected app to the front. This requires a pointer (IntPtr) to be passed, which I have available when populating my grid, but I can't see to keep around in IntPtr format. When I assign the IntPtr to a cell value, and then try to recast it as a pointer again, it bombs: _hWnd = (IntPtr)dgvTaskList.SelectedRows[0].Cells[2].Value; SetForegroundWindow(_hWnd); I need to either A) store a raw IntPtr in a cell (not as a string) B) be able to convert the string back to a ptr C) something else entirely that I'm not thinking of I'm open to any help or suggestions from my code project peers... Thanks! -- modified at 12:13 Tuesday 27th November, 2007
-
Hello, I'm writing a ALT+TAB-ish app that pops up due to a hotkey. It currently displays a list of currently running applications (using EnumWindows & GetWindowText) as a row in a DataGridView and I've created a event handler to run when a row is double clicked on. I'm hoping to use SetForeGroundWindow from User32.dll to bring the selected app to the front. This requires a pointer (IntPtr) to be passed, which I have available when populating my grid, but I can't see to keep around in IntPtr format. When I assign the IntPtr to a cell value, and then try to recast it as a pointer again, it bombs: _hWnd = (IntPtr)dgvTaskList.SelectedRows[0].Cells[2].Value; SetForegroundWindow(_hWnd); I need to either A) store a raw IntPtr in a cell (not as a string) B) be able to convert the string back to a ptr C) something else entirely that I'm not thinking of I'm open to any help or suggestions from my code project peers... Thanks! -- modified at 12:13 Tuesday 27th November, 2007
-
how about... _hWnd = new IntPtr(int.Parse(dgvTaskList.SelectedRows[0].Cells[2].Value)); Jeff
Holy cow man! _hWnd = new IntPtr(int.Parse(dgvTaskList.SelectedRows[0].Cells[2].Value.ToString())); ..worked. Thanks!