我有一个具有使用DataGrid的ItemsSource时结合DataGridTemplateColumn一个DataGrid,但在DataGridTemplateColumn的组合框,我希望能够绑定到视图模型的视图,而不是的ItemsSource.
<DataGrid ItemsSource="{Binding ModelValues, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
<DataGridTemplateColumn Header="myHeader" Width="200">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox DisplayMemberPath="Value" SelectedValuePath="Key" IsEnabled="False"
SelectedValue="{Binding myID, Mode=TwoWay}"
ItemsSource="{Binding Path=myList,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ViewModel}}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox DisplayMemberPath="Value" SelectedValuePath="Key" IsEnabled="False"
SelectedValue="{Binding myID, Mode=TwoWay}"
ItemsSource="{Binding Path=myList,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ViewModel}}}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)
ViewModel有一个ModelValues属性和myList属性.将ModelValues用于ItemsSource的DataGrid,我想用myList的ComboBox ItemsSource.
我如何更改RelativeSource命令以使其有效?
每当我尝试在mySchema中创建一个新的myObj时,它会一直告诉我ID是null,但是当我运行调试器时,调试器会告诉我正在添加的对象没有NULL值.它适用于我同事的机器,但不适用于我的......
MyObj myObj = new myObj() {
ID = 1234,
}
container.AddObject("MyObj", myObj);
container.ObjectStateManager.ChangeObjectState(myObj, System.Data.EntityState.Added);
// container extends ObjectContext as created by the EDMX
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
---------------------------
---------------------------
System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> Oracle.DataAccess.Client.OracleException: ORA-01400: cannot insert NULL into ("myModel"."myObj"."ID")
ORA-06512: at line 4
at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object …Run Code Online (Sandbox Code Playgroud) 目前,我有以下,从LDAP拉.
// Get context, based on currently logged on user
PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, Environment.UserDomainName);
// Search for the "Domain Users" group, with domain context
GroupPrincipal group = GroupPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, "Domain Users");
if(group != null) {
List<Principal> members = null;
members = group.GetMembers(false)
.OrderBy(principal => principal.Name).ToList();
List<Principal> Principals = members
.OrderBy(a => a.Name.Split(',')[0])
.ThenBy(a => a.Name.Split(',')[1])
.ThenBy(a => a.SamAccountName).ToList();
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,如果我有Doe,John它工作正常,但如果我有Admin01,它会崩溃,因为它找不到第二部分.如何更改它,如果它只有一个单词,它也会起作用?
C#语言的新手,我刚刚创建了一个贷款抵押计算器,我在下面格式化我的代码时遇到了问题.我想要做的是将每月付款值格式化为2位小数并添加"$"符号.任何帮助,将不胜感激.谢谢!
我的原则金额的示例输入:
//User input for Principle amount in dollars
Console.Write("Enter the loan amount, in dollars(0000.00): ");
principleInput = Console.ReadLine();
principle = double.Parse(principleInput);
//Prompt the user to reenter any illegal input
if (principle < 0)
{
Console.WriteLine("The value for the mortgage cannot be a negative value");
principle = 0;
}
//Calculate the monthly payment
double loanM = (interest / 1200.0);
double numberMonths = years * 12;
double negNumberMonths = 0 - numberMonths;
double monthlyPayment = principle * loanM / (1 - …Run Code Online (Sandbox Code Playgroud) 我想在c#mail中嵌入来自网址的图片,我尝试使用此代码,但它无效
LinkedResource logoHeader = null;
AlternateView av1 = AlternateView.CreateAlternateViewFromString(strBody, null, MediaTypeNames.Text.Html);
logoHeader= new LinkedResource("some xyz.com");
logoHeader.ContentId = "logoimage";
av1.LinkedResources.Add(logo);
Run Code Online (Sandbox Code Playgroud) 目前,我使用:
Variabls:
int recordCount = 5;
Header = "Index"; // Can also be "Starting Index"
Run Code Online (Sandbox Code Playgroud)
标题:
Header = Header.Split(' ')[0] + " (" + recordCount + ")";
Run Code Online (Sandbox Code Playgroud)
变化:
Index (5)
Run Code Online (Sandbox Code Playgroud)
至:
Index (6)
Run Code Online (Sandbox Code Playgroud)
当我想用新的Header替换Header时,我使用了上面的内容,但问题是当我开始使用多个单词时,Header它会删除Header Name的其余部分.即当它说Starting Index:它只显示Starting.
我可以使用正则表达式来简单地查找括号之间的值并将其替换为另一个变量吗?
我想在其他班级做某事时更新文本框。让我把我的代码:
namespace TestApp
{
public partial class Form1 : Form
{
CalledClass call = new CalledClass();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
call.Call_UpdateBox();
}
public void UpdateBox()
{
textBox1.Text = "hello";
}
}
}
Run Code Online (Sandbox Code Playgroud)
namespace TestApp
{
class CalledClass
{
public void Call_UpdateBox()
{
Form1 mainform = new Form1();
//do looping for doing some tasks here and update textbox every time
mainform.UpdateBox();
}
}
}
Run Code Online (Sandbox Code Playgroud)
当单击主窗体上的按钮时,调用 CalledClass 中的 Call_UpdateBox 函数,我必须在其中执行一些循环并在更新主窗体中的文本框之间进行。虽然如果我在调试模式下看到它的值,文本框会得到更新,但它在主窗体上仍然是空白的。请建议。提前谢谢。
我怎么做以下事情:
var query = from a in OBJ where a.ID == ID select c;
Run Code Online (Sandbox Code Playgroud)
它是<1秒,但是一旦我添加了IQueryable函数,它会增加到~3秒?
var query = (from a in OBJ where a.ID == ID select c).SingleOrDefault();
Run Code Online (Sandbox Code Playgroud)
当我使用FirstOrDefault()时也会发生同样的情况.
我应该在返回之前保存switch语句的结果吗?或者,当我得到它时,我应该在开关中返回值吗?有没有一种方式比另一种更好的风格?
使用临时变量:
public double xMax {
get {
double val = 0.00f;
switch(x_option) {
case 0:
val = priMax;
break;
case 1:
val = rfMax;
break;
case 2:
val = pwMax;
break;
}
return val;
}
}
Run Code Online (Sandbox Code Playgroud)
使用return语句:
public double xMax {
get {
double val = 0.00f;
switch(x_option) {
case 0:
return priMax;
case 1:
return rfMax;
case 2:
return pwMax;
}
}
}
Run Code Online (Sandbox Code Playgroud)
是否有性能差异和/或清理?
这是一个非常具体的问题,我需要在C#.NET中过去6个星期五的日期.目前,我们正在通过一个SQL数据库来完成此任务,该数据库的表格中包含了一年中星期五的日期.
这有两个问题,
1)当我非常确定C#可以做到这一点时,对数据库似乎是一个不必要的查询.
2)我必须记得在年底加入明年.
我已经浏览了网络,我确定在某个地方有一个帖子可以清楚地向我显示答案,但我似乎无法找到它!
我希望有人可以帮我解决这个问题的代码.
提前谢谢了!
c# ×10
.net ×1
binding ×1
coding-style ×1
datagrid ×1
datetime ×1
image ×1
inheritance ×1
itemssource ×1
linq ×1
odac ×1
oracle ×1
performance ×1
regex ×1
sorting ×1
string ×1
uri ×1
winforms ×1