如何在C#中输入Enter事件时在datagridview当前单元格中获取组合框 [英] how to get combobox in datagridview current cell on enter key press event in c#

查看:97
本文介绍了如何在C#中输入Enter事件时在datagridview当前单元格中获取组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友您好,请帮助我

让我的datagridview像这样.............

Hello friends please help me

let my datagridview is like this.............

id    name   subject    Class
1     a       maths     11
2     b       maths     11
3     c       maths     12
4     d       maths     11
5     e       science   10
6     f       science   11
7     g       science   12
____________________________


现在,我只想在用户仅按Enter键时才能在列主题中获得一个组合框(其中包含三个值的静态值,如数学,科学,艺术..)……以更改该特定学生的主题...我希望你现在能理解我的问题...

请朋友帮我
我该怎么办...请帮助我....


感谢高级

lakhan:(


Now I want to get a combo-box in column subject (which contain three values static value like maths ,science,arts..) only when user press enter key only....to chnage the subject of that particular student... I hope now you can understand my problem ...

please friend help me
what I have to do ...please help me ....


thanks in advanced

lakhan :(

推荐答案

您可以使用面板.将datagrid控件放入面板中.

现在在datagrid的cellclick上

将面板显示为弹出窗口,然后在面板上放置更新按钮.在datagrid中选择一行后,该特定行的所有数据将在面板控件上.当用户单击更新按钮更新表并绑定数据网格时选择主题.
you can use a panel. put your controls of datagrid into panel.

now on cellclick of datagrid

show your panel as popup and put update button on panel. After selecting a row in datagrid all data of that particular row will be on panel controls. after selecting subject when user clicks on update button update table and bind datagrid.


<datagrid name="dgSales" height="300" margin="0,3,0,0" issynchronizedwithcurrentitem="True" selecteditem="{Binding SelectedItem,Converter={StaticResource ignoreNewItemPlaceHolderConverter}}" itemssource="{Binding StockList,UpdateSourceTrigger=PropertyChanged}" tooltip="{Binding RelativeSource={RelativeSource Self},Path=(Validation.Errors)[0].ErrorContent}" gotkeyboardfocus="dgSales_GotKeyboardFocus" currentcellchanged="dgSales_CurrentCellChanged" previewkeydown="dgSales_PreviewKeyDown">
	<datagrid.columns>
		<datagridtextcolumn header="S No." width="SizeToCells" minwidth="60" binding="{Binding SNo}" isreadonly="True" />
		<datagridtemplatecolumn header="Stock Name" width="280">
			<datagridtemplatecolumn.celltemplate>
				<datatemplate>
					<textblock text="{Binding StockName}" />
				</datatemplate>
			</datagridtemplatecolumn.celltemplate>
			<datagridtemplatecolumn.celleditingtemplate>
				<datatemplate>
					<combobox width="280" name="cmbStock" itemssource="{Binding Path=Stocks}" focusmanager.focusedelement="{Binding RelativeSource={RelativeSource Self}}"></combobox>
				</datatemplate>
			</datagridtemplatecolumn.celleditingtemplate>
		</datagridtemplatecolumn>
		<datagridtextcolumn header="Unit Price" width="SizeToCells" minwidth="80" binding="{Binding UnitPrice,UpdateSourceTrigger=LostFocus}" />
		<datagridtextcolumn header="Unit" width="SizeToCells" minwidth="80" binding="{Binding Unit}" isreadonly="True" />
		<datagridtextcolumn header="Quantity" width="SizeToCells" minwidth="80" binding="{Binding Quantity,UpdateSourceTrigger=LostFocus}" />
		<datagridtextcolumn header="Discount" width="SizeToCells" minwidth="80" binding="{Binding Discount,UpdateSourceTrigger=LostFocus}" />
		<datagridtextcolumn header="Amount" width="SizeToCells" minwidth="100" binding="{Binding Amount,StringFormat=\{0:n2\}}" isreadonly="True" />
	</datagrid.columns>
</datagrid>


这篇关于如何在C#中输入Enter事件时在datagridview当前单元格中获取组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆