How can I make a messagebox or textbox pop up when a specific cell is double clicked in my DataGrid in C# WPF -


i have datagrid, i'm using c# wpf. want find way when user double clicks cell in last column textbox pops , displays of content in specific cell. there anyway possibly this? think there way

if (mydatagridobj.cellselected[i] in column)

{    stuff } 

i want give content of specific cell when user double clicks on specific cell. don't wwant pop though unless specific cell falls under column name , clicked. want give cell's content.

  1. we need handle mousedoubleclickevent cells.
  2. check if double-click happens in our desired cell.
  3. then need show textbox on our grid cell's data.
  4. if click anywhere on our grid outside textbox, textbox should hidden.

in example, double-clicking last column address column, textbox displayed.

below code can used :

<window x:class="wpfdatacontrols.datagrid._32792409.win32792409"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         title="win32792409" height="329.323" width="568.421">     <grid>         <grid.rowdefinitions>             <rowdefinition height="192*"/>             <rowdefinition height="107*"/>         </grid.rowdefinitions>         <grid.columndefinitions>             <columndefinition width="87*"/>             <columndefinition width="53*"/>         </grid.columndefinitions>         <datagrid x:name="dgrdemployees"  previewmousedown="grid_previewmousedown" horizontalalignment="left" margin="29,30,0,0" verticalalignment="top" height="148" width="305" loadingrow="dgrdemployees_loadingrow" />         <textbox x:name="tbdgrdcellcontent" visibility="hidden" width="200" height="100" horizontalalignment="left" margin="44,59,0,0" textwrapping="wrap" verticalalignment="top" background="#fffff3f3" borderthickness="4"/>     </grid> </window>  using system; using system.componentmodel; using system.collections.objectmodel; using system.collections.generic; using system.linq; using system.text; using system.windows; using system.windows.input; using system.windows.controls; using system.windows.controls.primitives; using system.windows.data; using system.diagnostics;  using system.windows.media;  namespace wpfdatacontrols.datagrid._32792409 {     /// <summary>     /// interaction logic win32792409.xaml     /// </summary>     public partial class win32792409 : window     {         public win32792409()         {             initializecomponent();              icollectionview view = collectionviewsource.getdefaultview(datastore.employees);             dgrdemployees.itemssource = view;         }          private void grid_previewmousedown(object sender, system.windows.input.mousebuttoneventargs e)         {             tbdgrdcellcontent.visibility = system.windows.visibility.hidden;                     }          private void dgrdemployees_loadingrow(object sender, datagridroweventargs e)         {             mousebuttoneventhandler handler = new mousebuttoneventhandler(dgrdcell_mousedoubleclick);             e.row.addhandler(datagridcell.mousedoubleclickevent, handler);         }          private void dgrdcell_mousedoubleclick(object sender, system.windows.input.mousebuttoneventargs e)         {             debug.writeline("double click");              datagridcellinfo cellinfo = dgrdemployees.currentcell;             datagridcolumn col = cellinfo.column;              if (dgrdemployees.columns.indexof(col) < dgrdemployees.columns.count - 1) return;              frameworkelement content = col.getcellcontent(cellinfo.item);              tbdgrdcellcontent.visibility = system.windows.visibility.visible;             tbdgrdcellcontent.text = ((textbox)content).text;             tbdgrdcellcontent.focus();         }      }      public class datastore     {         static observablecollection<employee> _employees;         public static observablecollection<employee> employees { { return _employees; } set { _employees = value; } }          static datastore() {             _employees = new observablecollection<employee>();             _employees.add(new employee() { name = "anjum", address = "nizamuddin" });             _employees.add(new employee() { name = "ashok", address = "bharat nagar" });             _employees.add(new employee() { name = "bashok", address = "bharat nagar" });             _employees.add(new employee() { name = "dashok", address = "bharat nagar" });             _employees.add(new employee() { name = "tashok", address = "bharat nagar" });             _employees.add(new employee() { name = "gashok", address = "bharat nagar" });          }      }      public class employee {          public string name { get; set; }         public string address { get; set; }              } } 

Comments