我在处理驻留在dataGridView中的comboBox的索引更改事件时遇到问题.我编写了一个方法来使用委托来处理comboBox选择更改:
ComboBox.SelectedIndexChanged -= delegate { ComboBoxIndexChanged(); };
ComboBox.SelectedIndexChanged += delegate { ComboBoxIndexChanged(); };
Run Code Online (Sandbox Code Playgroud)
或者一个EventHandler:
comboBox.SelectedIndexChanged += new EventHandler(ComboBoxIndexChanged);
Run Code Online (Sandbox Code Playgroud)
但这两种方法都没有按预期工作.也就是说,当您在comboBox中单击您的选择(包含在dataGridView中)时,需要多次单击才能生成我的ComboBoxIndexChanged(); 正常运行的方法,如果它决定完全起作用.克服/关于在dataGridView中的comboBox的indexedChange上指定事件的最佳方法是什么?
我目前在上下文中使用的代码如下:
private void dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
try
{
if (this.dataGridView.CurrentCell.ColumnIndex == (int)Column.Col)
{
ComboBox comboBox = e.Control as ComboBox;
if (comboBox != null)
{
comboBox.SelectedIndexChanged += new EventHandler(ComboBoxIndexChanged);
}
}
return;
}
catch (Exception Ex)
{
Utils.ErrMsg(Ex.Message);
return;
}
}
Run Code Online (Sandbox Code Playgroud)
并且事件ComboBoxIndexChanged是:
private void ComboBoxIndexChanged(object sender, EventArgs e)
{
// Do some amazing stuff...
}
Run Code Online (Sandbox Code Playgroud)
我已经在StackOverFlow上读了一个类似的线程,该线程表明以这种方式处理comboBox更改事件存在问题,但我无法使解决方案起作用.可以在此处找到帖子:Datagridview上的ComboBoxColumn中的"SelectedIndexChanged"事件.它说:
"事情变得复杂,因为他们通过对所有行只有一个编辑控件来优化DataGridView.这就是我处理类似情况的方式: …
我试图定义一个类.当我分配使用
this = blah blah
Run Code Online (Sandbox Code Playgroud)
编译器报告"这是只读"
当我将类更改为struct时,它看起来很好,任何想法?
我通过命名空间使用WPF Charting ToolKit:
xmlns:ChartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:VisualizationToolkit="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
Run Code Online (Sandbox Code Playgroud)
我有一个图表控件,在每次Lineseries绘图时我会生成一个随机颜色.我删除数据点标记并使用以下样式着色
<Style x:Key="LineDataPointStyle"
TargetType="ChartingToolkit:LineDataPoint">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Width" Value="NaN"/>
<Setter Property="Height" Value="NaN"/>
<Setter Property="Background"
Value="{Binding RelativeSource={RelativeSource Self},
Converter={StaticResource ColorBrushConverter}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ChartingToolkit:LineDataPoint">
<Grid x:Name="Root" Opacity="0"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
通过LineSeries定义
<ChartingToolkit:LineSeries Title="{Binding DisplayName}"
AnimationSequence="FirstToLast"
SnapsToDevicePixels="True"
DataPointStyle="{StaticResource LineDataPointStyle}"
ItemsSource="{Binding Data}"
IndependentValueBinding="{Binding X}"
DependentValueBinding="{Binding Y}"/>
Run Code Online (Sandbox Code Playgroud)
现在,这工作正常,但图例标记显示的颜色与我为其生成的随机颜色不同LineSeries.我希望为它LineSeries和它Lineseries自己的图例项目显示相同的颜色.所以,我将传说项目设置如下
<Style x:Key="TestSuiteLegendItemStyle"
TargetType="{x:Type ChartingToolkit:LegendItem}">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ChartingToolkit:LegendItem}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" …Run Code Online (Sandbox Code Playgroud) 我以为我会看看Caliburn.Micro.使用旧的CodePlex文档,我去实现我继承的bootstrapper类(继承自BootstrapperBase),新版本中没有BootstrapperBase/Bootstrapper类.GitHub
我已经重新下载了旧的CodePlex版本,我重新开始使用教程等,并且Bootstrapper可以使用这些类.
最新版本的Caliburn.Micro发生了什么,为什么没有Bootstrapper课程?
请注意,我看到:
这对我没有帮助.
我最近升级了我的代码库(Java,C++和C#)以使用proto3.在C#的情况下,这涉及对代码的2000多个更改.这大部分是语义的,都很好,但有一个问题我似乎无法理解; 序列化/反序列化.我有以下修改的方法来解除我的IMessage类型(在proto2中执行此操作的代码被注释),这是在GitHub存储库中的示例中显示的代码...
public static T ToObject<T>(this byte[] buf) where T : IMessage
{
if (buf == null)
return default(T);
using (MemoryStream ms = new MemoryStream())
{
ms.Write(buf, 0, buf.Length);
ms.Seek(0, SeekOrigin.Begin);
MessageParser parser = new MessageParser();
return (T)parser.ParseFrom(ms);
//ProtoBuf.Serializer.Deserialize<T>(ms);
}
}
Run Code Online (Sandbox Code Playgroud)
但该行MessageParser parser = new MessageParser();给了我一个设计/编译时错误
MessageParser不包含包含0个aguments的构造函数
好吧,我很好奇,因为我知道proto3文件告诉我相反的情况.
我想知道的是,使用proto3,我如何进行反序列化?
谢谢你的时间.
注意,我的序列化代码是
public static byte[] ToByteArray<T>(this T o) where T : IMessage
{
if (o == null)
return null;
using (MemoryStream ms = new MemoryStream()) …Run Code Online (Sandbox Code Playgroud) 我是Java的新手.我有时间从网页上获取,这是"hh:mm"格式(不是24小时).这对我来说是一个字符串.然后我想将这个字符串与今天的日期结合起来,以便创建一个Date我可以使用的Java .
在C#中:
string s = "5:45 PM";
DateTime d;
DateTime.TryParse(s, out d);
Run Code Online (Sandbox Code Playgroud)
在Java中我尝试过:
String s = "5:45 PM";
Date d = new Date(); // Which instantiates with the current date/time.
String[] arr = s.split(" ");
boolean isPm = arr[1].compareToIgnoreCase("PM") == 0;
arr = arr[0].split(":");
int hours = Integer.parseInt(arr[0]);
d.setHours(isPm ? hours + 12 : hours);
d.setMinutes(Integer.parseInt(arr[1]));
d.setSeconds(0);
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来实现我想要的?
我有下表
CREATE TABLE __EpiTest
(
`ActivityRecordID` int,
`ActCstID` varchar(6),
`ResCstID` varchar(6),
`VolAmt` int,
`ActCnt` int,
`TotOCst` int,
`TotCst` int
);
INSERT INTO __EpiTest (`ActivityRecordID`, `ActCstID`, `ResCstID`, `VolAmt`, `ActCnt`, `TotOCst`, `TotCst`)
VALUES (15652, 'DIM008', 'CPF005', 30.455249786377, 1, 0, 0.375024198767061),
(15652, 'DIM008', 'CSC004', 30.455249786377, 1, 7.62176510799961, 11.932578069479),
(15652, 'DIM008', 'REC001', 30.455249786377, 1, 0.17902367836393, 0.384881520159455),
(15652, 'OUT001', 'CPF002', 15, 0, 0, 16.9408193013078),
(15652, 'OUT001', 'CSC001', 15, 0, 2.36971564207042, 2.36971564207042),
(15652, 'OUT001', 'CSC004', 15, 0, 12.3230666021278, 12.3760690367354),
(15652, 'OUT001', 'REC001', 15, 0, 0.377459387378349, …Run Code Online (Sandbox Code Playgroud) 所有(这是回归基础!),我从SQL Server中获取了一串信息.字符串是这样的
Hello, my name is Frank Butcher\n\n
and I work at Watford Car lot,
and I am 65 years old.
Run Code Online (Sandbox Code Playgroud)
该消息将被拉入消息框以提供有关进程的信息.我用它读了字符串
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = 0;
cmd.CommandText = strSQL;
strResult = cmd.ExecuteScalar().ToString();
Run Code Online (Sandbox Code Playgroud)
这会得到字符串,但当我把它放到我的文本框中时,显示的消息\n\n没有所需的双NewLine.
我试过用
strResult = strResult.Replace("\n", Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)
在字符串上,但这没有帮助.我精神错乱,我做错了什么?
谢谢你的时间.
我有以下SQL Server存储过程:
CREATE PROCEDURE ispsDcOhcAgg @TmpTableName NVARCHAR(50), @ListItem NVARCHAR(50)
AS
IF EXISTS (SELECT name
FROM sys.tables
WHERE name = @TmpTableName)
DROP TABLE @TmpTableName; -- This will not work.
GO
Run Code Online (Sandbox Code Playgroud)
这显然不起作用(参见上面的snippit中的评论).我发现解决这个问题的唯一(也是非常丑陋的)方法是执行以下操作
CREATE PROCEDURE ispsDcOhcAgg @TmpTableName NVARCHAR(50), @ListItem NVARCHAR(50)
AS
DECLARE @SQL NVARCHAR(4000)
SET @SQL = N'IF EXISTS (SELECT name ' +
N'FROM sys.tables ' +
N'WHERE name = N' + N'''' + @TmpTableName + N''') ' +
N'DROP TABLE ' + @TmpTableName + N';'
EXEC sp_executesql @SQL;
GO
Run Code Online (Sandbox Code Playgroud)
真正发臭和大型存储过程,这是可怕的!
还有另一种我不知道的做法吗?
谢谢你的时间.
为了试图解决这个问题,我在DataGrid Scroll之后将Binding Selected RowCount绑定到TextBlock而不是Firing OnPropertyChanged ; 即TextBlock用DataGrid滚动时的当前所选行数更新a .我试图介绍AttachedCommandBehaviour由Marlon Grech设计的[一个惊人的类结构,允许您将命令绑定到给定控件的特定事件].
现在对于这个问题,使用这个AttachedCommandBehaviour,我怎样才能得到TextBlock基于a DataGrid的更新SelectionChangedProperty?
XMAL是
<Window x:Class="ResourceStudio.Views.AddCultureWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewModels="clr-namespace:ResourceStudio.ViewModels"
xmlns:converters="clr-namespace:ResourceStudio.Converters"
xmlns:dataAccess="clr-namespace:ResourceStudio.DataAccess"
xmlns:attachedCommand="clr-namespace:AttachedCommandBehavior;assembly=AttachedCommandBehavior"
Title="Add Culture"
Height="510" Width="400"
WindowStartupLocation="CenterOwner"
VerticalContentAlignment="Stretch"
MinWidth="380" MinHeight="295">
<DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="24"/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="15*"/>
<ColumnDefinition Width="377*"/>
<ColumnDefinition Width="15*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="1">
<Grid>
<Grid.Resources>
<converters:EnumToBooleanConverter x:Key="enumToBooleanConverter"/>
<Style x:Key="HyperlinkButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ContentPresenter/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> …Run Code Online (Sandbox Code Playgroud)